How to change default Requested for in catalog item

Serhii5
Mega Guru

Hi guys, could you help me, by default, when i try to order from catalog item field "requested for" filling by logged in user, i would like to change it from a variable ?

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Create a before business rule on table sc_request with below details.

Table: sc_request

 

When to run: Before

 

Insert: Checked

 

Advanced > Condition : Empty

 

Script:

 

var grRITM = new GlideRecord('sc_req_item');

 

grRITM.addQuery('request', current.sys_id);

 

grRITM.query();

 

while (grRITM.next()) {

 

  if (!JSUtil.nil(grRITM.variables.requested_for)) {   //assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.

 

      current.requested_for = grRITM.variables.requested_for; /assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.

 

  }

View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Create a before business rule on table sc_request with below details.

Table: sc_request

 

When to run: Before

 

Insert: Checked

 

Advanced > Condition : Empty

 

Script:

 

var grRITM = new GlideRecord('sc_req_item');

 

grRITM.addQuery('request', current.sys_id);

 

grRITM.query();

 

while (grRITM.next()) {

 

  if (!JSUtil.nil(grRITM.variables.requested_for)) {   //assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.

 

      current.requested_for = grRITM.variables.requested_for; /assuming requested_for is the name of your catalog variable. Replace this exactly with the name of catalog variable you have.

 

  }

This worked perfectly, however now I have the problem of it leaving the approvers related to the person who created it.  How do we address checking/changing the approving manager?

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have a look at the default value for the Requested for on Request.

Out-of-the-box default value:

javascript:gs.getUserID()

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

That's because the field has default value as logged in user in dictionary

find_real_file.png

if this is for your specific catalog item only then you can update it via the workflow on your catalog item with that variable value

Avoid using Business rule as this is only for your catalog item

Use Run Script activity in workflow

sample script below

Note: Ensure you use proper variable name

var user = current.variables.<variableName>;

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

req.requested_for = user;
req.update();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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