- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 06:22 AM - edited 04-28-2025 06:23 AM
Hi,
I have created 4 new Catalog variables Requested for User, Office Phone, Alternate Phone, Catalog Owner to the existing form. I have created catalog client script and script include for these variables (onLoad catalog client script and onChange catalog client script for Office Phone, and Alternate Phone) and onLoad for Catalog Owner.
I have updated the flow with all the new values, flow is working fine too.
These scripts are working fine and I am able to display at the form level. But the variable values are not getting displayed at the RITM level and SCTASK level. Kindly help.
onChangeClientScript for Phone Numbers
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('onChangePhoneNumbersClass');
ga.addParam('sysparm_name', 'onChangePhoneNumbersFunction');
ga.addParam('sysparm_Id', newValue);
ga.getXML(callBackFunction);
function callBackFunction(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var op = JSON.parse(answer);
g_form.setValue('office_phone', op.callerOfficePhone);
g_form.setValue('alternate_phone', op.callerAlternatePhone);
}
}
Script Include for Phone Numbers
var onChangePhoneNumbersClass = Class.create();
onChangePhoneNumbersClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onChangePhoneNumbersFunction: function() {
var keyPhone = this.getParameter('sysparm_Id');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', keyPhone);
gr.query();
if (gr.next()) {
var jsonObj = {};
jsonObj.callerOfficePhone = gr.getValue('phone');
jsonObj.callerAlternatePhone = gr.getValue('mobile_phone');
var json=new JSON().encode(jsonObj);
return json;
}
},
type: 'onChangePhoneNumbersClass'
});
onLoad for Phone Numbers
function onLoad() {
var ga = new GlideAjax('onLoadPhoneNumbersClass');
ga.addParam('sysparm_name', 'onLoadPhoneNumbersFunction');
ga.addParam('sysparm_ID', g_user.userID);
ga.getXML(callBackFunction);
function callBackFunction(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var op = JSON.parse(answer);
g_form.setValue('office_phone', op.callerOfficePhone);
g_form.setValue('alternate_phone', op.callerAlternatePhone);
}
}
Script Include for onLoad Phone Numbers
var onLoadPhoneNumbersClass = Class.create();
onLoadPhoneNumbersClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoadPhoneNumbersFunction: function(){
var keyPhone = this.getParameter('sysparm_ID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', keyPhone);
gr.query();
if(gr.next()){
var jsonObj={};
jsonObj.callerOfficePhone=gr.getValue('phone');
jsonObj.callerAlternatePhone=gr.getValue('mobile_phone');
var json=new JSON().encode(jsonObj);
return json;
}
},
type: 'onLoadPhoneNumbersClass'
});
onLoad for Catalog Owner
function onLoad() {
var sys = g_form.getUniqueValue();
var ga = new GlideAjax('onLoad_Owner_RU');
ga.addParam('sysparm_name', 'onLoad_Owner_Function');
ga.addParam('sysparm_id', sys);
ga.getXML(callBackFunction);
function callBackFunction(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('catalog_owner', answer);
}
}
Script Include for Catalog Owner
var onLoad_Owner_RU = Class.create();
onLoad_Owner_RU.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoad_Owner_Function: function(){
var keyOwner = this.getParameter('sysparm_id');
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', keyOwner);
gr.query();
if(gr.next()){
return gr.getDisplayValue('owner');
}
},
type: 'onLoad_Owner_RU'
});
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 06:39 AM
why are you running them on RITM and Catalog task level?
Uncheck these 2 checkboxes and you will start seeing those values on RITM and SC Task form
g_form.getUniqueValue() won't work on RITM and SC task form -> it will give record sysId and not catalog item sysId
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 06:39 AM
why are you running them on RITM and Catalog task level?
Uncheck these 2 checkboxes and you will start seeing those values on RITM and SC Task form
g_form.getUniqueValue() won't work on RITM and SC task form -> it will give record sysId and not catalog item sysId
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 06:48 AM
Hi @Ankur Bawiskar,
I have this question since long time. When do we check these checkboxes?
As per the uniqueVlue, it is correct right. Here I am looking for the sys_id of the catalog item. and in the script include i am looking for the sys_id in sc_cat_item which matches the sys_id and gets me the owner, for which I used getDisplayValue('owner'). It is working perfectly fine.
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 06:51 AM
those checkboxes are used when you want same validation to run when RITM or SC Task is opened as compared to catalog form
Also those checkboxes helps you to write catalog client script on RITM and SC Task for your item and access variable values using g_form.getValue('variableName');
Simply uncheck those and you are good with your question asked.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader