- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 11:21 AM
Hello!
I need to access a value from the grandparent of a record through a Client Script. I don't want to use a GlideRecord. Is there a way of doing so?
These are the relations: CHG (grandparent), RITM (parent), SCTASK (where I'm standing). I need to get to the grandparent's state and sys_class_name values. Here's my code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var parent = g_form.getReference('request_item', callback);
function callback(parent) {
var grandparent = parent.parent; // This stores the sys_id of the parent as a string.
// If I could dot-walk through the grandparent's values, the script would work perfectly.
if (!grandparent && grandparent.sys_class_name != 'change_request') {
return;
}
if (grandparent.state != 3 && newValue == 3 || newValue == 4 || newValue == 7) {
g_form.setValue('state', 1);
g_form.showFieldMsg('state', 'Please close the related change', 'error');
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 07:31 PM
It's recommended to load everything which the client script will need for sure on server side and then send the data with the help of the g_scratchpad to the client.
There are many articles and videos aqround that topic available, for example Display Business Rule and g_scratchpad
And an extensive explanation by ServiceNow can be found at https://docs.servicenow.com/bundle/washingtondc-application-development/page/script/client-scripts/c...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 07:31 PM
It's recommended to load everything which the client script will need for sure on server side and then send the data with the help of the g_scratchpad to the client.
There are many articles and videos aqround that topic available, for example Display Business Rule and g_scratchpad
And an extensive explanation by ServiceNow can be found at https://docs.servicenow.com/bundle/washingtondc-application-development/page/script/client-scripts/c...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 10:14 PM
Hello @conradofonseca ,
Best way to achieve this is using scratchpad variable. You can write a Display Business Rule and populate the g_scratchpad variable, since you are specific about what information you need. Then retrieve this variable in the client script.
Display BR :
g_scratchpad.sys_class_name = 'Value';
g_scratchpad.state = 'Value';
Client Script :
var sys = g_scratchpad.sys_class_name;
var state = g_scratchpad.state = 'Value';
If my answer solves your issue, please mark it as Accepted ✔️ and Helpful 👍 based on the impact.