Variable values are seen on the form but not on RITM, SCTASK

Dave_p
Giga Guru

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

 

1.png

 

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

 

2.png

 

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

 

3.png

 

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

 

4.png

 

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

 

5.png

 

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

 

6.png

 

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'
});

 

7.png

 

8.png

 

9.png

 

10.png

 

Regards

Suman P.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

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

AnkurBawiskar_0-1745847285250.png

 

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.

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

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

AnkurBawiskar_0-1745847285250.png

 

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.

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

Dave_p
Giga Guru

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.

@Dave_p 

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.

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