- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:18 AM
What is the best way to call system property in a client script (script include) for a catalog item ???
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:36 AM
Hi,
you cannot get system property value in client side directly.
you need to use GlideAjax for this and return the property value from the ajax function
Example
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
return gs.getProperty('property_name'); // name of property here
},
type: 'checkRecords'
});
Client Script:
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.getXMLAnswer(function(answer){
if(answer != ''){
alert(answer); // this gives you the property value
}
});
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-10-2022 05:43 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
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-08-2022 06:37 AM
Hello Rathan,
You can call gs.getProperty("property_name") in script include. But if you are looking to call the System property in Client script then you can use something like below code:
Client Script:
Please user the below code in your Display BR:
g_scratchpad.group = gs.getProperty("user.group.name");
Once you store the property value in scratchpad object you can use it in client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_scratchpad.group) {
g_form.setValue("group", g_scratchpad.group);
}
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 06:42 AM
For Catalog Client script you cannot use the Display BR. You have to use the GlideAjax() to call the script include and then read the property fetched in response:
var CustomerPropertyUtils = Class.create();
CustomerPropertyUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPropertyValue: function(){
return gs.getProperty('user.group.name'); // Provide your property name here;
},
type: 'CustomerPropertyUtils'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax("CustomPropertyUtils");
ga.addParam("sysparm_name", "getPropertyValue");
ga.getXMLAnswer(parseResponseData);
function parseResponseData(answer){
if(answer != ''){
g_form.setValue("group", answer);
}
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 06:01 AM
Hello Rathan,
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.
If you still need any further help or guidance on this then please update those on this question.
Thanks
