
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 12:25 AM
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!!!
Solved! Go to Solution.
- Labels:
-
Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 12:27 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 01:51 AM
Yeah, you can't dot walk in client scripts. I would advise against using getReference(), it returns the entire record to the client when you only need 1 field from it. Glide Ajax it considered best practice, you call a server side script include and do all the processing there. Happy to help with config but the guide below is really good and it's really important to know how to configure this so i'd recommend having a look.
https://community.servicenow.com/community?id=community_blog&sys_id=f8ccee25dbd0dbc01dcaf3231f961978

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 03:07 AM
Thanks, I'm going to check it in deep, it's a little bit complex at the beginning, so I would like to make the things working as soon as possible first 🙂
May I ask you to support me using getReference()?
Thanks a lot
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 03:54 AM
Not sure what's wrong, it looks like the script is written properly. What field are you running this on the change of? It might be worth running it onLoad and also try returning the value of a string field instead.
One important thing to note is that the account field on the task form is itself a reference field. Even if you get your getReference working, it will only be returning a sys_id. If you want to get the name/display value you have to go into the customer_account table and getReference only allows you to go into the referenced table. To go two tables deep you'll need Glide Ajax, something like this:
//client script
var ga = new GlideAjax('ScriptIncludeName');
ga.addParam('sysparm_name', 'functionName');
ga.addParam('sysparm_task', g_form.getValue('task');
ga.getXMLAnswer('getAjaxData');
function getAjaxData(response){
g_form.setValue('u_account_ref', response);
}
//script include
functionName: function(){
var tsk = this.getParameter('sysparm_task');
var gr = new GlideRecord('sn_customerservice_case');
if(gr.get(tsk)){
return gr.getDisplayValue('account');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 04:30 AM
Thanks David, I'm going to use GlideAjax then, still something not correct, I tried to use your example, please help:
// client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('test');
ga.addParam('sysparm_name', 'test_function');
ga.addParam('sysparm_task', g_form.getValue('task'));
ga.getXMLAnswer('getAjaxData');
function getAjaxData(response){
g_form.setValue('u_account_ref', response);
}
}
//script include
function test_function(){
var tsk = this.getParameter('sysparm_task');
var gr = new GlideRecord('sn_customerservice_case');
if(gr.get(tsk)){
return gr.getDisplayValue('account');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 05:12 AM
When you're writing the script include, open a new record and enter the name and it will populate the script field with some syntax, tick the client callable checkbox and it will change that syntax to the ajax prototype. end product should look like this:
var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
test_function: function(){
var tsk = this.getParameter('sysparm_task');
var gr = new GlideRecord('sn_customerservice_case');
if(gr.get(tsk)){
return gr.getDisplayValue('account');
}
},
type: 'test'
});