Getting "undefined" while passing string data into another string field

venkysana
Tera Expert

Need to auto populate APM Number of issue (sn_grc_issue) form from entity field which is reference to profile (sn_grc_profile) table. I am getting "undefined" in APM Number field as shown in below.

find_real_file.png

I have written below script include and onload client script but no use. Please help me to achieve this.

Script Include:

var autopopulateentityAPMnumber = Class.create();
autopopulateentityAPMnumber.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {


    getAPMnumber: function() {

        var object = {};

        var num = this.getParameter('sysparm_sys');
        var appGr = new GlideRecord('sn_grc_profile');
        appGr.addQuery('sys_id', num);
        appGr.query();
        if (appGr.next()) {
            object.u_amp_number = appGr.u_amp_number.toString();
        }

        val = JSON.stringify(object);
        return val;

    },

    type: 'autopopulateentityAPMnumber'
});

 

OnLoad Client Script:

function onLoad() {
	
	var ga = new GlideAjax('autopopulateentityAPMnumber');
	ga.addParam('sysparm_name', 'getAPMnumber');
	ga.addParam('sysparm_sys', g_form.getValue('profile'));
	ga.getXML(callBackFunction);
	
	function callBackFunction(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		var val = JSON.parse(answer);
		
		g_form.setValue('u_amp_number', val.u_amp_number);
	}

}
20 REPLIES 20

@Ankur Bawiskar  I already suggested that but the requirement is to auto populate the number into string field. Any suggestion on this?

Hi,

I will still inform customer to avoid creating extra field when the task is just to auto-populate and show

so what's not working?

on form load are you sure the entity reference field is populated?

Regards
Ankur

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

Yes entity reference field is populating even if we are creating new record.

Hi,

How are you auto-populating it when form loads?

did you check if you get sysId in script include

Regards
Ankur

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

vandna
Tera Guru

Try different variable name instead of object. Object could cause and issue because it is an keyword and check if g_form.getValue('profile') is returning the sysid of the grc profile.