- 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:15 AM
You cannot access values by dot walking in client script so offloc.country is not working in your case.
You will have to write GlideAjax to fetch that country value by passing location to script include.
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:16 AM
Thankyou. Can you help me with sample code please?
- 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:23 AM
Hello,
Try using getReference using callback method as below
var location = g_form.getReference('office_location', doAlert); // doAlert is our callback function
function doAlert(location) { //reference is passed into callback as first arguments
alert(' country is: ' + location.country);
}
check for alert if value is right for country and then add your if logic
Thanks,
Valmik