- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 07:37 AM
In the Catalog items i have a field name property (ref to sys_properti and list collector )
and another variable --> value
using the script inlcude what i select in the property field --> that particular value should be seen in the value field.
but the value of the particular property is not coming. what is wrong with the script?
catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getPropertyValue');
ga.addParam('sysparm_name','getRecords');
ga.addParam('sysparm_groupId',newValue); //Parameters
ga.getXML(cb);
function cb(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('value', answer);
}
}
Script include:
var getPropertyValue = Class.create();
getPropertyValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecords:function()
{
var groupSysId = this.getParameter('sysparm_groupId');
gs.addInfoMessage(groupSysId);
var obj = {};
var grSysUser = new GlideRecord('sys_properties');
grSysUser.addQuery('name', groupSysId);
grSysUser.query();
while (grSysUser.next()) {
obj[grSysUser.name.value.getDisplayvalue()] = grSysUser.name.toString();
}
gs.addInfoMessage(grSysUser.value);
return JSON.stringify(obj);
},
type: 'getPropertyValue'
});
i need the particular property value should be displayed in JSON format
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 11:11 PM
Hello @demoutah
Adjusted your code little bit.Highlighted in Bold and Green
Catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getPropertyValue');
ga.addParam('sysparm_name','getRecords');
ga.addParam('sysparm_groupId',newValue); //Parameters
ga.getXMLAnswer(cb);
function cb(answer) {
//var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('value', result.value);
}
}
Script include:
var getPropertyValue = Class.create();
getPropertyValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecords:function()
{
var groupSysId = this.getParameter('sysparm_groupId'); // as this is a list collector
gs.addInfoMessage(groupSysId);
var obj = {
name:'',
value:'',
};
var grSysProp = new GlideRecord('sys_properties');
grSysProp.addEncodedQuery('sys_idIN'+ groupSysId);
grSysProp.query();
while (grSysProp.next()) {
//obj[grSysUser.name.value.getDisplayvalue()] = grSysUser.name.toString();
obj.name = grSysProp.getDisplayValue().toString(); // optional if you want name of property also
obj.value = grSysProp.getValue('value').toString();
}
//gs.addInfoMessage(grSysUser.value);
return JSON.stringify(obj);
},
type: 'getPropertyValue'
});
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:20 PM
@demoutah The exact same question has been answered in below thread
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 11:11 PM
Hello @demoutah
Adjusted your code little bit.Highlighted in Bold and Green
Catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getPropertyValue');
ga.addParam('sysparm_name','getRecords');
ga.addParam('sysparm_groupId',newValue); //Parameters
ga.getXMLAnswer(cb);
function cb(answer) {
//var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('value', result.value);
}
}
Script include:
var getPropertyValue = Class.create();
getPropertyValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecords:function()
{
var groupSysId = this.getParameter('sysparm_groupId'); // as this is a list collector
gs.addInfoMessage(groupSysId);
var obj = {
name:'',
value:'',
};
var grSysProp = new GlideRecord('sys_properties');
grSysProp.addEncodedQuery('sys_idIN'+ groupSysId);
grSysProp.query();
while (grSysProp.next()) {
//obj[grSysUser.name.value.getDisplayvalue()] = grSysUser.name.toString();
obj.name = grSysProp.getDisplayValue().toString(); // optional if you want name of property also
obj.value = grSysProp.getValue('value').toString();
}
//gs.addInfoMessage(grSysUser.value);
return JSON.stringify(obj);
},
type: 'getPropertyValue'
});
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 11:43 PM - edited 02-16-2023 11:45 PM
@Vishal Birajdar @jaheerhattiwale
Catalog client script: