Glide Ajax and Script Include for sysID

Community Alums
Not applicable

Hi,

The task is to get sysID of the record and put into another variable. I am getting the output as null via addInfoMessage.

 

Script Include

 

sysID1.PNG

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

	var ga = new GlideAjax("onChangeStChSysIDClass");
    ga.addParam("sysparm_name", "onChangeStChSysIDFunction");
    ga.addParam("sysid_key", newValue);
    ga.getXML(callBackFunction);

    function callBackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		g_form.addInfoMessage("answer is " + answer);
        g_form.setValue("standard_change_template_sys_id", answer);
    }
	
}

 

Script Include

 

var onChangeStChSysIDClass = Class.create();
onChangeStChSysIDClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	onChangeStChSysIDFunction:function(){
		var keyClientScript = this.getParameter("sysid_key");
        var userId_DB = "";
        var userGR = new GlideRecord("std_change_template");
        userGR.addQuery("sys_id", keyClientScript);
        userGR.query();
        if (userGR.next()) {
            userId_DB = userGR.getValue("sys_id");
            return userId_DB;
		}
	},

    type: 'onChangeStChSysIDClass'
});

 

Employee_Center1.PNG

 

Regards

Suman P.

1 ACCEPTED SOLUTION

yes please write that code in onchange client script.

 

g_form.getValue('standard_change_template')

as this is reference field it returns sysid by default. 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

View solution in original post

7 REPLIES 7

@Community Alums are you facing any issue, is it working fine

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

Anurag Tripathi
Mega Patron
Mega Patron

Try this

 

Client Script

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

	var ga = new GlideAjax("onChangeStChSysIDClass");
    ga.addParam("sysparm_name", "onChangeStChSysIDFunction");
    ga.addParam("sysparm_sysidkey", newValue);
    ga.getXML(callBackFunction);

    function callBackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		g_form.addInfoMessage("answer is " + answer);
        g_form.setValue("standard_change_template_sys_id", answer);
    }
	
}

 

Script include

var onChangeStChSysIDClass = Class.create();
onChangeStChSysIDClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	onChangeStChSysIDFunction:function(){
		var keyClientScript = this.getParameter("sysparm_sysidkey");
        var userId_DB = "";
        var userGR = new GlideRecord("std_change_template");
        userGR.addQuery("sys_id", keyClientScript);
        userGR.query();
        if (userGR.next()) {
            userId_DB = userGR.getValue("sys_id");
            return userId_DB;
		}
	},

    type: 'onChangeStChSysIDClass'
});
-Anurag

Pavankumar_1
Mega Patron

Hi @Community Alums ,

your are passing the sysid to server and getting the same sysid. But script is correct i didn't see any error.

try below don't required script include

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    g_form.setValue("standard_change_template_sys_id", newValue); //newValue stores the reference sysid
}

 

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar