Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to populate a Reference field automatically (no dot-walking, GlideAjax)

Alberto Consonn
ServiceNow Employee

Hi guys,

I need an help for configuring the Advanced Reference Qualifier in the right way.

In the Time Worker table, I've created a Reference custom field "Account_ref" to the customer_account table.

I would like to fill this field automatically with the account of the selected task, I tried dding with the following Advanced Reference Qualifier...no luck.

javascript:'account='+current.task;

Thanks for your help!!!

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Dubz
Mega Sage

Hi Alberto,

I replicated your config and figured out the issue, real rookie error for which i accept full responsibility 🙂

The function call in the getXMLAnswer() line is in quotes, it shouldn't be! use this:

//client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}

	var ga = new GlideAjax('TestScriptInclude');
	ga.addParam('sysparm_name', 'testFunction');
	ga.addParam('sysparm_task', g_form.getValue('task'));
	ga.getXMLAnswer(getAjaxData);

	function getAjaxData(response){
		g_form.setValue('u_account_ref', response);
	}
}

 

EDIT: Just noticed Harsh has already picked this up! 

View solution in original post

36 REPLIES 36

Alberto Consonn
ServiceNow Employee

Hi David,

I tried to use the following onChange client script but it's raising the error below:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   var task = g_form.getValue('task');
	g_form.setValue('u_account_ref', task.account.name);
}

find_real_file.png

Any idea?

Thanks a lot

 

 

dot walk will not work here, until you use callback function in your client script. A

The Fantastic g_form getReference Callback

 

try using callback function

I tried but still getting "undefined" with the below code, could you please help me?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   //Type appropriate comment here, and begin script below
   var task = g_form.getReference('task', setAccount);
}

function setAccount(task) {

    if (task)
        g_form.setValue('u_account_ref', task.account);

}

find_real_file.png

can you give a try again

 

g_form.getReference('task', cbFunc);

function cbFunc(gr) {
    var test= gr.getValue('account');
    alert('Value is ' +test); 
}

 

 

i tested this way and its working for me.