Can someone help me understand SetStorageVar and GetStorageVar?

SOLVED

I'm trying to use a script to store the ShipToAddress1, 2, and 3 field values prior to having a script fire off a button click which does an address validation through a 3rd party plugin. I have the address validation working. However, I cannot get the address fields to store. It always comes back blank.

I'm currently trying like this on the SO_SalesOrderHeader object on the address tab's on exit UI script event

sAddressLine1 = "" : sStoreShipTo1 = ""

retVal = oBusObj.GetValue("ShipToAddress1$", sAddressLine1)

retVal = oScript.SetStorageVar("sStoreShipTo1", sAddressLine1)

Then after the address validation it overwrites our address fields, which I want to overwrite with my saved variables. Don't ask... its a tax deal... all thats important for the tax calc is the zip + 4.

To reintroduce the saved values I was trying later at the end of the script to do:

retVal = oScript.GetStorageVar("sStoreShipTo1", sAddressLine1)

retVal = oBusObj.SetValue("ShipToAddress1$", sAddressLine1)

I'm sure I'm doing this completely wrong or there is a better way to go about it so I'm all ears for any helpful links, or advice you all may have.

Thanks in advance!

  • +1
    verified answer

    I think you are doing everything okay, except where you are using the script.  I would use a business logic script to invoke this, possibly on the pre-write of the sales order or something to that effect.   If you are firing this off when the UI is exiting then the record is no longer being edited.  I would most likely attach this to the pre-write of the Sales Order Header business logic.  

    The business logic scripting events are found in the User-Defined Field and Table Maintenance.  Select the SO Sales Order Header table and go to User-Defined Scripts... and add your script in the Table Pre-Write event for the table.  Again, I'm not sure of everything your script is trying to do, but this seems to me to be the best place for your script.

    Hope this helps

    Elliott

  • 0 in reply to jepritch

    Strange question that your comment made me think about... Is the scripting object between UI scripts and business logic scripts the same?

    I want to use a UI script to invoke the address validation or people get really confused when they get an error about addresses when they have hit the totals tab and are trying to save the order. There is no business script event that holds the user to the respective tab until proper info is entered that I've experienced.

    I tried column post-validate but wasn't successful. I guess in a business script I could just force them back to the tab with InvokeButton("fldr.pAddress") over and over until they enter a valid value...

  • +1 in reply to EArter
    verified answer

    @EArter I missed something about your previous post that you attached it to the Address tab's on-exit method, which got me to thinking, and this should work.   I thought you had it attached to the exit of the entire sales order screen.

    I just did a quick test and it seems to work for me, but I'm not calling any external service for validation.   The script object itself belongs to a specific Sage 100 object, so the SO_SalesOrder_ui will have it's own instance of a script object, and the business object it's own, if that makes sense.

    Is all of this in one script?  Or does it cross scripts?

    E

  • 0 in reply to jepritch

    Yeah I finally got my SetStorageVar and GetStorageVar to work as well, it was some weird syntax issue I wasn't catching. But I still have a problem. Originally my plan was to put this in one script. The 3rd party address validation basically hits an API of this company, and that API bounces the address against the USPS database and corrects the address if its wrong.

    Its pretty snappy, but not as fast as the script. So my problem now is that the script does good and kicks off the address validation, but the validation although only seconds takes longer than the script and it overwrites my address values even after I try to replace the API services values at the end of my script or in a second script. 

    Not sure if that reads well... essentially I'm trying to compensate for a lack of knowledge in timing of the API service to complete with two scripts, but that didn't work. I don't have good contact with the API's developers or I'd figure out the executable and put it in a run program call so the script would know when the API has finished its call. 

    I was thinking today maybe I would try and use a "has the API ran" boolean variable or something like that in one script and run a second script to recall my original address values. I haven't had time to think through the "what-ifs" of someone trying to edit an order that needed an address change though. I.E. Created the order to go to one place, realized it was wrong and updated the order.

    Sorry for the rambling...I like context...