The CreatorCon Call for Content is officially open! Get started here.

How to get two reference field in client script?

PhoenixMing0912
Giga Expert

Hi all,

For example, A and B are reference fields of incident. I want to compare A.a and B.b in client script, how can I do that?

I know g_form.getReference() but looks like only one reference field can be fetched.

 

Regerds,
Eric

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

Assuming you want to compare some other fields based on the reference field of A and B, you can do liek this.

var a = g_form.getReference("A"); //put correct field names

var b = g_form.getReference("B"); //put correct field names

if(a.your_field == b.your_field) {

//do something.

}

Mark the comment as a correct answer if it solves your problem.

View solution in original post

5 REPLIES 5

Simon Westwood
ServiceNow Employee
ServiceNow Employee

From a performance perspective, you'd be better off using an AJAX call which takes the 2 sys_id's as input as in Ankur's example.  This will mean there will only be 1 round trip to the server instead of the 2 needed for getReference.  It will also minimise the amount of data returned, getReference will return every field while an AJAX call will leave the data on the server and could just return a true or false.