
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 08:27 AM
I need to change/set the requested_for field in a Requested Item so the Tasks emails contain the proper information.
I've made a script and placed it in both a Run Script as well as the Advanced tab for an SC_Task in a workflow.
I used the following script which appears to work (the log shows the right information), but the form still has the wrong user name:
current.requested_for = current.variables.Request_for_User;
current.requested_by = current.variables.Request_for_User;
current.update();
gs.log("FIRST RUN SCRIPT: Current Number/request_for/requested_by:" +current.number+'/'+current.requested_for.getDisplayValue()+'/'+current.requested_by.getDisplayValue());
Any suggestions?
Mike
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 09:03 AM
As it's on the request table you can try
var req = new GlideRecord('sc_request');
req.get(current.request);
req.requested_for = current.variables.requested_for_user; // or whatever the variable is called
req.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 09:00 AM
Hello Mike,
Requested for is a field on "Request" table. You can follow the below approach instead.
You can create a BEFORE business rule on sc_request table with the script as
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.sys_id);
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.Request_for_User)) {
current.requested_for = grRITM.variables.Request_for_User;
}
}
})(current, previous);
OOTB I don't see requested_by field on Request table. Is this a custom field on your form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 09:03 AM
As it's on the request table you can try
var req = new GlideRecord('sc_request');
req.get(current.request);
req.requested_for = current.variables.requested_for_user; // or whatever the variable is called
req.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 06:51 AM
Scott's answer is correct. The RITM (where the workflow is running) inherits the requested_for from its generating request. Changing the requested_for on the RITM will not work, but if you change the requested_for on the request, the requested_for on the RITM will update as well. Unfortunately, this means if you cannot change the requested_for on only one RITM if a request has more than one RITM (for example, "Add to cart" was used from the service catalog).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 02:36 PM