- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 11:45 AM
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);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:08 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 12:50 PM
Hi Luis,
Can you please use alert('Testing: ' + ret.location); as a first statement in callback function. Just trying to debug your script.
A couple of things I want to know;
- Are you sure that you have used the correct variable name in g_form.getReference() ?
- ret.location will return the sys_id of location, so if you are setting this value in a reference variable then it is fine , otherwise you will have to use GlideAjax to get the display value of location.
For learning purpose, getReference() only supports one-level of dot walking.
Hopefully, we will resolve this query together.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 01:10 PM
Khan I put the alert as you indicated. Get the message "Testing:undefined". What I know is that the
newValue has the value of the selected asset id. Any other suggestion, please.
Luis
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try {
g_form.getReference('assigned_asset', callback);
function callback(ret) {
alert('Testing: ' + ret.location);
g_form.setValue('location', ret.location);
alert('Testing after:' + ret.location);
}
} catch (ex) {
g_form.addErrorMessage(" TYPE [on assigned_asset Change] encountered the error: " + ex.message);
g_form.addInfoMessage("TYPE [on assigned_asset Change] encountered the error:" + ex.message);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 01:19 PM
Can you share screenshot of your variable details on which you have implemented this client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 01:40 PM