- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 06:43 AM
Hi,
I'm trying to change a field in the requested item table from the workflow. Here is my script:
var p = new GlideRecord('sc_req_item');
p.addQuery('sys_id', current.sys_id);
p.query();
while(p.next()){
p.requested_for = current.variables.name;
p.update();
}
I think my problem is with getting the right item. Can anyone help please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 01:44 PM
I agree with you that you must be a little confused on which requested_for you are actually using.
There are TWO requested_for fields, one in the sc_req_item table and the other on the sc_request one.
In your script you are indeed modifying the one on the sc_req_item table but your RITM form maybe showing the request.requested_for one so you don't see it changing because in reality the one in the request table is not being changed. Check the screens below... I modified the RITM form on my developer instance to show both at the same time and they are indeed different.
So your script is modifying the green information but your form most likely is displaying the yellow information.
Use the "show function" (right click on top of the field) to show what you are actually displaying.
I included the code below with some explanations.
var request = new GlideRecord('sc_request');
request.get(current.request); //current is the ritm you are using, then you use the info in the request field of that ritm. Using GET gets you the exact glide record of the request you are looking for. No need to use .query() or .next()
request.requested_for = current.variables.name; //make sure .name is a sys_id in the sys_user table
request.update();
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 07:07 AM
Hi @Snow Tomcal,
The Requested for field/column of Requested item form is from Request table. Hence update it on Request table.
Try this sample scripts here -
var req = new GlideRecord('sc_request');
req.get(current.request);
req.requested_for = current.variables.name;
req.location = current.variables.variables.location;
req.update();
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 01:44 PM
I agree with you that you must be a little confused on which requested_for you are actually using.
There are TWO requested_for fields, one in the sc_req_item table and the other on the sc_request one.
In your script you are indeed modifying the one on the sc_req_item table but your RITM form maybe showing the request.requested_for one so you don't see it changing because in reality the one in the request table is not being changed. Check the screens below... I modified the RITM form on my developer instance to show both at the same time and they are indeed different.
So your script is modifying the green information but your form most likely is displaying the yellow information.
Use the "show function" (right click on top of the field) to show what you are actually displaying.
I included the code below with some explanations.
var request = new GlideRecord('sc_request');
request.get(current.request); //current is the ritm you are using, then you use the info in the request field of that ritm. Using GET gets you the exact glide record of the request you are looking for. No need to use .query() or .next()
request.requested_for = current.variables.name; //make sure .name is a sys_id in the sys_user table
request.update();
If I helped you with your case, please click the Thumb Icon and mark as Correct.