Populate phone type variable based on location table parent field .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 12:56 AM
Hi All,
In catalog items, I have a work location variable referencing the location table. If the parent field in the location table is set to 'United Kingdom,' then the phone type variable should be visible on the catalog items form. Does anyone have an idea on how to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 03:08 AM
I can try this requirement in script include and catalog client script , but it didn't work for me. can you have any idea on how to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 03:29 AM
try this
var GetLocationParent = Class.create();
GetLocationParent.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getParent: function() {
var locationSysId = this.getParameter('sysparm_location_sys_id');
var locationGr = new GlideRecord('cmn_location');
locationGr.addQuery('sys_id' ,locationSysId );
if (locationGr.next())
//if (locationGr.get(locationSysId))
{
return locationGr.parent.getDisplayValue(); // Convert to uppercase for case-insensitive comparison
}
return '';
},
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:05 AM
Hi @suha2,
Whilst a response in this thread provides an example that is easy to code / copy, namely the use of getReference, this is an example of inefficient code. (Even with a callback)
Instead, substitute the use of getReference(), (or GlideRecord lookup) with an asynchronous GlideAjax call.
See ServiceNow Technical Best practices and examples here:
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie