Get Value of variable

mregragui_ext
Tera Contributor

Hi,

I want to get the value of the "Select the software/system" and fill a field in the form of the RITM with this value.

variable value.png

2 ACCEPTED SOLUTIONS

Hi @mregragui_ext 

 

If you are using "gr.get()" , you need to use sys_id of that record

 

 

 

var mrvs;
var itemID = 'ab223sajnjsb7r3rr4t';   //set here sys_id of ritm record 
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
mrvs = ritmGR.variables.var1;
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

 

 

                                                     OR

 

Try this

 

var mrvs;
var itemID = "RITM0010246";  
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('number',itemID);
ritmGR.query();
if (ritmGR.next()) {
mrvs = ritmGR.variables.var1;
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

By the looks of it u_business_application is a reference field, it will only take the value of var1 if it is present on the table it references.

Can you add logs like below and show that values you get

var mrvs;
var itemID = 'RITM0010246';
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
gs.print('came here 1');
mrvs = ritmGR.variables.var1;
gs.print('mrvs  = '+ mrvs );
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

Once you get the value of mvrs, try to set the same thing on u_business_application on form and see if you can do it manually.

 

-Anurag

View solution in original post

12 REPLIES 12

Peter Bodelier
Giga Sage

Hi @mregragui_ext,

 

You can do that within the flow or workflow for this catalog item.

Which are you using?

 

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Vishal Birajdar
Giga Sage

Hi @mregragui_ext 

 

Need some more information like...

1.Which table "Select the software/ system" is referencing ..?

2.On which condition the variable should filled means any dependency on other variable

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

@Vishal Birajdar 

1.Which table "Select the software/ system" is referencing ..?

the table is business application

2.On which condition the variable should filled means any dependency on other variable

when the user is creating a ritm in the service portal there is a formular with a filed called Select the software/system then this field get dispaly with variable formatter in the form of the ritm i want to get the value of this variable and fill the Business app with this value if Select the software/system is not empty 

BA.png

Hi @mregragui_ext 

 

You can use run script activity within workflow & try below script :

 

 

/*1. Get value of "select the software/ system" variable*/
var getSoftSyst = current.variables.<your_variable_name>;   // "select the software/ system" variable backend name

/*2. Update the current ritm Business application if software/system */

if(getSoftSyst != ''){
current.business_app = getSoftSyst;    // use the backend value of "Business application" field
}

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates