g_form.getReference() is not working in Service Portal

Siva Kedari Vee
Mega Guru

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

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

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);
		}
	}

}

 

 

View solution in original post

6 REPLIES 6

Harsh Vardhan
Giga Patron

use call back function with getReference() then it will work. 

 

getReference(String fieldName, Function callBack)

 

reference:

https://developer.servicenow.com/dev.do#!/reference/api/orlando/client/c_GlideFormAPI#r_GlideForm-Ge...

Harsh Vardhan
Giga Patron

other way is, use g_form.getValue('business_application_number') and pass it in your glide ajax as parameter and then in script include do the glide record to get "u_bit_correlation_id"

Harsh Vardhan
Giga Patron

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);
		}
	}

}

 

 

Thank you so much, it worked for me!!!