- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 12:08 PM
I'm having issues with the 'request_for' field on the catalog task form not working in my client script.
this client script has been used on the incident/RITM/change and interction form.
i tied to use 'sc_task.request_item.requested_for' and its still not working.
can anyone guide me on how to get this to work.
I've attached screen shots
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 02:28 PM
No worries, let's try this.
Create a Display Business Rule with the following script:
(function executeRule(current, previous /*null when async*/) {
//Use one of the following 2 options:
g_scratchpad.grade_of_service = current.request_item.requested_for.u_grade_of_service;
//OR if you want to invoke your script include, you can do the following
g_scratchpad.grade_of_service = new UserUtils().getGradesOfService(current.request_item.requested_for.toString());
})(current, previous);
Note that you can use either line of script.
Then within your client script:
//Replace the original script from line 7 to 17 with the following
if (g_scratchpad.grade_of_service == 'elite') {
g_form.showFieldMsg('request_item.requested_for', 'This user is Elite', 'error');
} else {
g_form.hideFieldMsg('request_item.requested_for');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 01:21 PM - edited 06-12-2024 01:22 PM
Hi @DevtoSME,
A few things to note:
- From the [sc_task] table, you are dot-walking to the [sc_req_item] record and then fetching the requested_for. That means you will need to use g_form.getReference('request_item.requested_for')......
- Using getReference is not a preferred way of fetching data, as it results in a transfer of unnecessary data. Instead, you can either use g_scratchpad or AJAX to fetch the data from the server in a more efficient manner - https://docs.servicenow.com/bundle/washingtondc-application-development/page/script/client-scripts/c...
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 01:47 PM
Ok i used g_scratcpad and im stll not getting a field message. this client script worked for the other tables so i want to know if the field name that im using is the issue.
i tried using 'request_item.requested_for and 'sc_task.request_item.requested_for not working.
Do you know if that is the issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 01:55 PM
Can you share what you have done for the g_scratchpad? (BR and Client Script)
In regards to the request_item.requested_for, I tried the following, and works fine. If you can share the script as well, I can have a look.
g_form.getReference('request_item.requested_for', function (userGr){
alert(userGr.name);
})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 02:16 PM