Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

What is the best way to call system property in a client script (script include) for a catalog item ???

Rathan1
Tera Contributor

What is the best way to call system property in a client script (script include) for a catalog item ???

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

@Rathan 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Mahendra RC
Mega Sage

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

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

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