Is there a way to get sys_id of user from reference variable to script include without using GlideAjax and getReference?

snow_dev
Tera Expert

Hi,

I want to pass sys_id of a selected user in reference variable from catalog item to script include without using client side scripting like GlideAjax or getReference method? Kindly suggest.

 

 

1 ACCEPTED SOLUTION

snow_dev
Tera Expert

Nevermind. I was able to get sys_id of user using following line of code instead of passing existing variable from one function to another.

var xyz = current.variables.<reference_variable_name>

 

View solution in original post

3 REPLIES 3

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Well, it depends on where/when you are using the script include.

Hi,

I have a variable (say x) in function A of a script include. This variable x has the value of sys_id of user.

I have another function B and I want to pass value of variable x from function A to function B.

I am able to do that but when I pass variable x to function B, along with sys_id value, it also passes an "undefined" value. 

Could you help me figure out why it is passing an "undefined" value and how to get rid of it?

Here is the script include:

Script Include

Function A

==================================

A: function() {


//gs.info('sysid of user from catalog item reference variable '+ obj);
x = this.getParameter('sysparm_requested_for');

//Passing value of variable x to another function B

this.B(x);

 

}

 

B:function(x)

{

var y = x;

//gs.info(y) returns two values 1. sys_id of user and 2. undefined

.....

//follows to an outbound rest message which sends query parameter by using value of y

response.setQueryParameter('sysparm_query','user='+y);

}

 

So, here I want to get rid of 'undefined' value so that I can pass value of y as a query parameter. Could you please suggest?

snow_dev
Tera Expert

Nevermind. I was able to get sys_id of user using following line of code instead of passing existing variable from one function to another.

var xyz = current.variables.<reference_variable_name>