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

priyasunku
Kilo Sage

Hi @Community Alums 

 

you can directly map it instead of using script include

 

g_form.setValue("standard_change_template_sys_id", g_form.getValue('standard_change_template'));

 

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

Community Alums
Not applicable

Hi @priyasunku ,

Do I put it in onChange client script? 

Regards

Suman P.

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

Community Alums
Not applicable

Hi @priyasunku 

I just used this

 

var sysID = g_form.getValue('standard_change_template').toString();
g_form.setValue("standard_change_template_sys_id",sysID );

 

Regards

Suman P.