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.

how to call system property in catalog client script.

Devaceis
Tera Contributor

Hello Developers,

Requirement - I have to create a client script for in some catalog item On hold state should be there and for other catalog item on hold state should not be there.

Condition- I have to create a system property , in the system property there is a field as Value. in value filed I have to pass catalog item sys_id. whichever sys_id is present in System property VALUE field for that on hold should be for other item on hold should be not there.

 

What I did to get to done this requirement -

I have created - system property. script include , client script.

system property -

Devaceis_0-1679896310379.png

Script Include -

Devaceis_1-1679896378349.png

Client Script-

Devaceis_2-1679896413763.png

What Problem I am getting -

problem is that for every catalog item On HOLD state is coming. whenever in system property only two item sys_id 

I have Passed , so idealy  only for two catalog item On hold state should be come.

So please help me to solve this problem.

Thanks and regards.

1 ACCEPTED SOLUTION

manjusha_
Kilo Sage

@Devaceis 

 

Use below client script and script include-

Client Script-

function onLoad() {
//Type appropriate comment here, and begin script below
//alert("hell0");
var item= g_form.getValue('cat_item');
var grAjax = new GlideAjax('GetCatalogId');
grAjax.addParam('sysparm_name','getProperty');
grAjax.addParam('sysparm_cat_item',item);
grAjax.getXML(getDemo);
function getDemo(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("hellresult"+item);
alert("SCRIPTRESULT"+answer);
if(answer=='true'){
 
g_form.addOption('state','5','On Hold Reason');
// g_form.removeOption();
}
else{
g_form.removeOption('state','5')
}
}
}

 

Script include- client callable 

var GetCatalogId = Class.create();
GetCatalogId.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getProperty: function() {
var retResult = false;
var i = 0;
var item = this.getParameter('sysparm_cat_item');
var cat_property = gs.getProperty('test_cat_item');
var result = cat_property.split(',');
for (i = 0; i < result.length; i++) {
if (result[i] == item) {
retResult = true;
return retResult ;
} else {
if (i == ((result.length) - 1)) {
return retResult;
}
}
}
},
type: 'GetCatalogId'
});

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact
 
Thanks,
Manjusha Bangale

 

View solution in original post

2 REPLIES 2

manjusha_
Kilo Sage

@Devaceis 

 

Use below client script and script include-

Client Script-

function onLoad() {
//Type appropriate comment here, and begin script below
//alert("hell0");
var item= g_form.getValue('cat_item');
var grAjax = new GlideAjax('GetCatalogId');
grAjax.addParam('sysparm_name','getProperty');
grAjax.addParam('sysparm_cat_item',item);
grAjax.getXML(getDemo);
function getDemo(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("hellresult"+item);
alert("SCRIPTRESULT"+answer);
if(answer=='true'){
 
g_form.addOption('state','5','On Hold Reason');
// g_form.removeOption();
}
else{
g_form.removeOption('state','5')
}
}
}

 

Script include- client callable 

var GetCatalogId = Class.create();
GetCatalogId.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getProperty: function() {
var retResult = false;
var i = 0;
var item = this.getParameter('sysparm_cat_item');
var cat_property = gs.getProperty('test_cat_item');
var result = cat_property.split(',');
for (i = 0; i < result.length; i++) {
if (result[i] == item) {
retResult = true;
return retResult ;
} else {
if (i == ((result.length) - 1)) {
return retResult;
}
}
}
},
type: 'GetCatalogId'
});

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact
 
Thanks,
Manjusha Bangale

 

Devaceis
Tera Contributor

@manjusha_

Thanks , It working Now.