- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2021 09:47 AM
In an onChaneg script when Business Application is populated i used a g_form.getRefrence() to return the value of the Bit Correlation ID field (“u_bit_correlation_id”) from the record and then pass it into a script include to query the table “sn_apm_business_app_additional_fields” and return the value for the field “u_pmp_2020_attestation” from it and populate it in PnP attestation if the value returned is Null OR empty. Production data is NOT present in any non-production environment” then return an error message and show a variable Label
Everything is working as desired but the g_form.getReference() is not working in portal and throws an error message to the console. Can some one help me to fix this
************************On change Client Script***************************
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setVisible('no_exception_found_please_update_applab_pnp_section_before_request', false);
return;
}
var bit_Id = g_form.getReference('business_application_number').u_bit_correlation_id;
//alert('The Bit ID is: '+ bit_ID);
var ga = new GlideAjax('populatePnpAttestation');
//ga.addParam('sysparm_name', 'getPnpAttestation');
ga.addParam('sysparm_bit_co_id', bit_Id);
ga.addParam('sysparm_bit_co_id', value);
ga.getXML(callBack);
function callBack(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert('The PnP Attestation is: '+ answer);
g_form.setValue('pnp_attestation', answer);
if(answer == null || answer == ''){
g_form.setVisible('no_exception_found_please_update_applab_pnp_section_before_request', true);
} else{
g_form.setVisible('no_exception_found_please_update_applab_pnp_section_before_request', false);
}
}
}
**************************Client Callable Script Include*******************************
var populatePnpAttestation = Class.create();
populatePnpAttestation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getBitID: function(){
var businessApp = this.getParameter('sysparm_business_app');
var bitId = '';
var gr1 = new GlideRecord('cmdb_ci_business_app');
gr1.addQuery('sys_id', businessApp);
gr1.addQuery('install_status', '1');
gr1.query();
if(gr1.next()){
bitId = gr1.u_bit_correlation_id;
}
return bitId;
},
getPnpAttestation: function(){
var bit_co_id = this.getParameter('sysparm_bit_co_id');
var pnp_attestation = '';
var gr = new GlideRecord('sn_apm_business_app_additional_fields');
gr.addQuery('u_business_application.u_bit_correlation_id', bit_co_id);
gr.query();
if(gr.next()){
pnp_attestation = gr.u_pmp_2020_attestation;
}
return pnp_attestation;
},
type: 'populatePnpAttestation'
});
I tried the same using another glide Ajax and it is somehow not working, Can someone help me to fix the issue
Regards,
Siva Kedari
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2021 09:56 AM
updated script with getReference call back function.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setVisible('no_exception_found_please_update_applab_pnp_section_before_request', false);
return;
}
var bit_Id = g_form.getReference('business_application_number', myFunc);
function myFunc(bit_Id){
//alert('The Bit ID is: '+ bit_ID);
var ga = new GlideAjax('populatePnpAttestation');
//ga.addParam('sysparm_name', 'getPnpAttestation');
ga.addParam('sysparm_bit_co_id', bit_Id.u_bit_correlation_id);
ga.addParam('sysparm_bit_co_id', value);
ga.getXML(callBack);
}
function callBack(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert('The PnP Attestation is: '+ answer);
g_form.setValue('pnp_attestation', answer);
if(answer == null || answer == ''){
g_form.setVisible('no_exception_found_please_update_applab_pnp_section_before_request', true);
} else{
g_form.setVisible('no_exception_found_please_update_applab_pnp_section_before_request', false);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2021 09:57 AM
Hello,
getReference alone, will not work on the Service Portal. As mentioned, you'd have to use a call back function and this has been the case for years (you can search the forums easily for: getReference not working on Service Portal and find many, many threads about it with correct answers marked), example: https://community.servicenow.com/community?id=community_question&sys_id=13edf68ddb5033841cd8a345ca96...
For your GlideAjax, please use log statements and let us know where you're seeing issues. Currently, I don't see any listed anywhere.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2021 10:04 AM
Another question, i have observed you are not calling your script include method in client script, i can see it has commented in your client script ? please uncomment it this way your method will get invoked .
//ga.addParam('sysparm_name', 'getPnpAttestation');
I would suggest avoid getReference with call back function, and use glide record in script include to get display value and ID.
Go with my second response.
Let me know if you need any further help.