EDIT: Items 1 & 2 solved
I wanted to explore calling (and retrieving a result from) a MSSQL stored Procedure.
Just a learning example... pass an ItemID and let it do a simple calc. Then return something.
Here's my working code:
I have this in Server-Side Events in a UX control.
In the afterDialogValidate function.
I understand that the preferred method for JS code is to move them into the JS functions CODE section, rather than have lots of JS code fragments directly attached to buttons, etc.
1) How does one do this for a XBasic function?
I can bring up an empty function window, and paste in what I've written above, but I need a "function xxx as ..." wrapper and I don't know what to put.
The afterDialogValidate function starts with this: function afterDialogValidate as v (e as p)
Do I pass "e" to my new XBasic function? Having trouble with syntax.
2) Now, once I've written this function to call the SP I also might want to call it other places, which is why I'm trying to get it moved out of the afterDialogValidate function. Then I can simply call it from a button.
I don't see how I will have the "e" structure available to me inside the XBasic function (if I call it from a button on a UX) so I think I need to pass IN the ItemID? instead of having it access "e.dataSubmitted.itemid" as it is written now.
3) For now, I am showing a JS Alert. I didn't really want this but its a way to test the SP result. I wanted to stuff the answer into a control on the UX. But I can't seem to make that happen.
a) I don't know how to properly reference a control (I thought it was e.control.myvar)
b) Maybe whats happening is that the ExecuteServerSideAction is set to "Edit record just submitted", so I think I might be setting the discount value correctly into a control, but its getting erased when the controls refresh after the rec was saved.
ideas appreciated, thx
jim
I wanted to explore calling (and retrieving a result from) a MSSQL stored Procedure.
Just a learning example... pass an ItemID and let it do a simple calc. Then return something.
Here's my working code:
Code:
DIM session.UserID as c DIM DiscountPrice as N dim cn as sql::connection dim args as sql::arguments dim rs as sql::ResultSet 'session.UserID = a5ws_getcurrentuser() 'once we start logging in session.UserID = "jimwwID" args.set("itemid",convert_type(e.dataSubmitted.itemid,"N" )) args.set("theUser",session.UserID ) args.set("discountprice",-1,sql::ArgumentUsage::InputOutputArgument) cn.Open("::Name::bruce") cn.Execute("EXEC calcext :itemid, :theUser, :discountprice",args) if (rtc.flagRecordWasSaved) then e.javascript = e.javascript + "alert('Discount price is $' + " + convert_type(round(args[3].data,2),"C") + ");" + crlf() end if
I have this in Server-Side Events in a UX control.
In the afterDialogValidate function.
I understand that the preferred method for JS code is to move them into the JS functions CODE section, rather than have lots of JS code fragments directly attached to buttons, etc.
1) How does one do this for a XBasic function?
I can bring up an empty function window, and paste in what I've written above, but I need a "function xxx as ..." wrapper and I don't know what to put.
The afterDialogValidate function starts with this: function afterDialogValidate as v (e as p)
Do I pass "e" to my new XBasic function? Having trouble with syntax.
2) Now, once I've written this function to call the SP I also might want to call it other places, which is why I'm trying to get it moved out of the afterDialogValidate function. Then I can simply call it from a button.
I don't see how I will have the "e" structure available to me inside the XBasic function (if I call it from a button on a UX) so I think I need to pass IN the ItemID? instead of having it access "e.dataSubmitted.itemid" as it is written now.
3) For now, I am showing a JS Alert. I didn't really want this but its a way to test the SP result. I wanted to stuff the answer into a control on the UX. But I can't seem to make that happen.
a) I don't know how to properly reference a control (I thought it was e.control.myvar)
b) Maybe whats happening is that the ExecuteServerSideAction is set to "Edit record just submitted", so I think I might be setting the discount value correctly into a control, but its getting erased when the controls refresh after the rec was saved.
ideas appreciated, thx
jim
Comment