- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 05:09 AM
Hi All,
My requirement is: In my catalog item, under variable set there are two fields
1- Office Location - reference to location table
2-Service to the user - select box with ChoiceA and ChoiceB
Now if the office location.country == FR, then service to the user should display ChoiceA
Else reverse.
Can someone guide me where did i do wrong.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 05:28 AM
Use below client script and script inlcude :
Script inlcude :
Script for you to copy:
Script Inlcude :
var getCountry = Class.create();
getCountry.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCountrybyLocation: function() {
var location = this.getParameter("location");
var grLocation = new GlideRecord("cmn_location");
if (grLocation.get(location)) {
return grLocation.country;
}
},
type: 'getCountry'
});
Client Script :
//Type appropriate comment here, and begin script below
var location = "25ab9c4d0a0a0bb300f7dabdc0ca7c1c";
var locationAjax = new GlideAjax("global.getCountry");
locationAjax.addParam("sysparm_name", "getCountrybyLocation");
locationAjax.addParam("location", location);
locationAjax.getXMLAnswer(callback);
function callback(response) {
alert(response);
}
I have used static variable in client script for storing location, you just need your 'offloc' variable there. Tested this on PDI and it is working fine.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 05:32 AM
Hey,
getReference method fetches whole row instead of just one country value therefore it is not considered as best approach in this case. You can use it only when you need multiple values from location.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 05:34 AM
Thanks!! It worked