Set Reference variable value to another variable value in a catalog item.

Balaram7
Kilo Sage

Hi all, 

We have a requirement to set Reference variable value similar to the value on the other reference field in catalog.

These two variables are from different variable sets, where they will refer to User(sys_user) table.

Request details is the first variable set.

Request for is the variable name - reference to User table.

Callback details is another Variable set.

Callback to is the variable name - reference to User table.

 

We need to set value of Request for == Callback to, when the request for value is Updated in the catalog request.

Please help me with the best approach, to achieve this.

Thank you, 

Balaram.

 

 

 

 

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

As long as they are both on the form, and both a reference field to the same table, you can simply create an onchange script for the Request for variable to set the value of the other: 

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

   g_form.setValue('callback', newValue);
   
}

Just make sure you have the variable name correct for callback (you need the name, not the label). 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You can write onChange client script on the variable "Request for"

Applies to Variable Set - Select your Request Details Variable set

Then select the variable name

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
	
	if(newValue == ''){
	 g_form.clearValue('callBackVariable'); // use valid variable name
	}
	
	g_form.setValue('callBackVariable',newValue); // use valid variable name
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Balaram 

Did you mistakenly mark other answer as correct? As I see same script was provided before from my end pretty well (first).

You can mark only 1 response as correct.

So please mark appropriate response as correct and helpful.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Balaram 

Did you mistakenly mark other answer as correct? As I see same script was provided before from my end pretty well (first).

You can mark only 1 response as correct.

So please mark appropriate response as correct and helpful.

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Michael Jones -
Giga Sage

As long as they are both on the form, and both a reference field to the same table, you can simply create an onchange script for the Request for variable to set the value of the other: 

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

   g_form.setValue('callback', newValue);
   
}

Just make sure you have the variable name correct for callback (you need the name, not the label). 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!