Set variable value to RITM

Geeky
Kilo Guru

Hi All,

I have a variable set which has two variables - Requested For and Requested By (Reference to user table).

I want to set the values of these variables to the Requested For and Opened by fields of RITM.

I do not want to specify in the workflow since in all of the workflow these workflow is used I need to modify all of those workflows.

Is there a way I can write a script at a variable set level so that code will be applied in all of the catalogs in which this variable set is used?

1 ACCEPTED SOLUTION

So did a quick test.

Business Rule
Table: sc_req_item
Insert = true
When: Async

Condition:

current.request.requested_for != current.variables.requested_for

Script:

(function executeRule(current, previous /*null when async*/) {

	var grREQ = new GlideRecord('sc_request');
	grREQ.get(current.getValue('request'));

	grREQ.setValue('requested_for', current.variables.requested_for);
	grREQ.update();
		
})(current, previous);

Works instantly.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You could set up a before insert business rule on the sc_req_item table. Would that be something for you?

Do note, requested for out-of-the-box is used on the Request, not on the Requested Item. So below code won't just work if you copy/paste. Maybe you have a custom field? Or maybe indeed you are actually after the Request. That's up to you.

Something like below:

current.requested_for = current.variables.requested_for;

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Is there OOTB Business Rule for request to set Requested For? From where the system gets requested for value? I understand if it's requested by then the default value is set as currently logged in user.

That's coming from the Service Portal widget.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Requested for field is an extended field from sc_request table. so, below statement is not working.

current.request.requested_for = current.variables.requested_for;

Even I tried with GlideRecord but no luck. My variable name is right. It is inside a variable set.

//current.request.requested_for = current.variables.requested_for;
	var gr = new GlideRecord('sc_request');
	gr.addQuery('sys_id',current.request);
	gr.query();
	current.comments = current.request;
	current.comments = gr.getRowCount();
	while(gr.next())
		{
	current.comments = gr.number;		
	gr.requested_for = 	current.variables.requested_for;
	gr.update();
		}