Catalog Client Script - Platform VS Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2022 05:12 PM
I have a requirement for a Service Catalog Item where, when the user populates the Manager field, we need to automatically populate a field which represents the manager of the manager, in other words, the person 2 levels up in the organization.
Everyone says "Use AJAX. Do NOT use the client-side GlideRecord object. OK. I get that. I hear you. But that is NOT my question. I repeat, that is NOT my question." Here are my questions, please:
1) Why is it that GlideRecord works on the Platform (client side) but not on the Portal (client side)? What is fundamentally different which causes it to NOT work on the Portal?
2) For an arbitrary Object or Function, what is the correct or most reliable way to determine whether or not it can be used in the Portal?
(By the way, I find it very strange that it's not just DOCUMENTED which functions do and do not work on the portal. Or am I missing something???)
Here is my code:
Here are the results on the client-side Platform UI, where everything works and the manager's manager field gets populated as required:
And here are the results on the client-side Portal UI, where the code crashes and burns, the angels cry, and there's gnashing of teeth:
Now I will go use Ajax, but I would still very much appreciate a better understanding, if someone could answer my two questions. May the gods smile upon you. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2022 11:14 PM
Hello
I believe that the GlideRecord in Service Portal Catalog Client script should work fine as per the ServiceNow product documentation:
Also the below KB Article mention that the GlideRecord does work in Service Portal client script:
GlideRecord Client API does not work in the Service Catalog standard UI but works in Service Portal
Also you can refer this below community question
Catalog Client Script on Service Portal is not working
So in your code you need to have a callback function as shown in below example:
var now_GR = new GlideRecord('incident');
now_GR.addQuery('priority', '<=', 2); // Priority is 2 or higher and,
now_GR.addQuery('short_description', 'CONTAINS', 'crash'); // Short description contains the word crash
now_GR.query(response);
function response(result) {
while(result.next()) {
// Print all INC with priority of 2 or higher AND short description contains "crash"
console.log(result.getValue('number'));
}
}
If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2022 10:30 PM
Hello
Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2022 10:37 PM
Hello
It's recommended to use GlideAjax or use GlideRecord with callback in client side.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2022 05:24 AM
Thanks