Getting "undefined" while passing string data into another string field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 05:46 AM
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.
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 03:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 03:57 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 04:44 AM
Yes entity reference field is populating even if we are creating new record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 06:49 AM
Hi,
How are you auto-populating it when form loads?
did you check if you get sysId in script include
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 03:58 AM
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.