How to get the location from the asset table using asynchronous script?

Luis Roman1
Tera Contributor

I have a catalog form with label named "assigned_asset" when the submitter select an asset id in the catalog item, I need to have an OnChange script for the "assigned_asset" and pull the location from the asset table. I need to have a script asynchronous so that it does not impact the user experience and it is "best practice". I have the script below but not able to get anything back. Any help appreciated. Or should I try to do a Glide Ajax to pull the information? Please advise or let me know what need to do to fix the script my experience scripting is very limited.  Thank you for advise or guidance. 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    try {
       g_form.getReference('asset', callback);            /* asset table */    
function callback(ret) {
          g_form.setValue('location', ret.location);
          }
    } catch (ex) {
        g_form.addErrorMessage(" TYPE [on Asset Change] encountered the error: " + ex.message);
        g_form.addInfoMessage("TYPE [on Asset Change] encountered the error:" + ex.message);
    }
}

1 ACCEPTED SOLUTION

As far as I know, getReference() only works with reference fields/variables, so it will not work with Lookup SelectBox. I would recommend you to use GlideAjax for this requirement.

View solution in original post

9 REPLIES 9

As far as I know, getReference() only works with reference fields/variables, so it will not work with Lookup SelectBox. I would recommend you to use GlideAjax for this requirement.

Ok. If I change the variable to a Reference then when display the catalog item I am able to select the field but does not bring them back to the screen.  

Khan, thank you for your patience and guidance. 

Luis 

Sorry I didn't get what you mean by "Does not bring them back to the screen."

 

THat's correct. Sorry

Glad it helped.