Help with business rule that updates the "Requested For" field on a requested item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 09:16 AM
Hi guys,
We had some help several months ago to create the following script.
(function executeRule(current, previous /*null when async*/) {
var on_behalf = current.variables.requested_for;
if(!!on_behalf){
var gr = new GlideRecord('sc_request');
gr.get(current.request);
gr.requested_for = on_behalf;
gr.update();
}
})(current, previous);
It's run on the sc_req_item table on each insert.
The intention is to take the name from the "requested_for" variable on the form, and then use this to replace the name in the "Requested For" field on the RIT record.
This generally seems to work well, but we recently found an issue if the same item is requested for a few different people, added to the cart and then submitted.
For example, if I request a laptop for Person A, add to card, then request a laptop for Person B, add to cart, and then submit the order.
This results in a "unique key violation" error message. The request is generated. The 2 RIT items are generated, but they end up being for the same person (e.g. Person A), and one of the RITs will be stuck in a "pending approval" stage.
Wondering if anyone could please advise me on the script above or things to try?
Thanks,
Chiu
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 09:29 AM
If there are 2 RITMs (for different people) with 1 Request then how can you put two different name in requested_for field. I think, in your case there should be 1 RITM per request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 12:11 PM
Hi, so to give an example of what we're trying to achieve...
John is an admin in the Finance department.
He wants to order 3 wireless headsets for Adam, Mark and Richard.
So he adds 1 wireless headset to the cart, specifying that it's for Adam on the item form. Then adds 1 wireless headset, specifying that it's for Mark and adds it to the cart. Then adds 1 wireless headset, specifying that it's for Richard and then adds it to the cart.
So the cart has 3 wireless headsets, John is the requester, but the headsets are requested for Adam, Mark and Richard.
In this scenario, John has taken it upon himself to request these for other members of the team.
John remains as the person who opened the request (REQ), but the 3 RITs that are open need to be updated so that the "Requested For" field is populated with Adam, Mark and Richard (taken from the "on behalf of" variable on the form).
Hope this helps to make more sense of it.
Thanks,
Chiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 12:28 PM
Requested For column on sc_req_item is derived from sc_request table.
Since you have only 1 requested for for sc_request, same requested for the request will be copied over to requested item.
You can pull variables ( for requested for) for your catalog item in sc_req_item and sc_task table so that you can who is requested for all 3 requested items.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 09:14 PM
Keep in mind by default there is no 'requested_for' attribute on the [sc_req_item] table. The [sc_request] table is the only OOB place a 'requested_for' attribute exists.
