- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 08:22 AM
We currently have a Business Rule that will pull the user from the requested_for or who_requested variables on the catalog item and updated the Requested For field of the Request with that user. Of course, this poses issues if you open multiple catalog items for various people within one request.
We're adding a custom u_requested_for field to the sc_req_item table and would like a Business Rule that sets the u_requested_for based on who was entered in the requested_for or who_requested variables on the catalog item.
I tried altering the existing BR but had no luck. Here is the existing BR for the Request table. I just need it updated so that it works on the Requested Item (sc_req_item) table.
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)) {
current.requested_for = grRITM.variables.requested_for;
}
if (!JSUtil.nil(grRITM.variables.who_requested)) {
current.requested_for = grRITM.variables.who_requested;
}
}
I tried changing the table to the sc_req_item table and updated the script but it didn't work. I tried a couple other versions but no luck.
var grRITM = new GlideRecord('sc_req_item');
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) {
current.u_requested_for = grRITM.variables.requested_for;
}
if (!JSUtil.nil(grRITM.variables.who_requested)) {
current.u_requested_for = grRITM.variables.who_requested;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 09:04 AM
Hi Alexander,
Make the business rule you have written active false.
Write an async type business rule in the sc_req_item table.Script should be like:
updateRequestedFor();
function updateRequestedFor(){
if(current.variables.requested_for !=''){
current.u_requested_for = current.variables.requested_for ;
}
else{
current.u_requested_for = current.variables.who_requested ;
}
current.update();
}
Mark it as Helpful/Correct if it helps
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 01:42 PM
Thank you for the detailed response Sumeet.
I have not personally made any async BR's, or any BR's affecting the sc_request or sc_req_item tables, so it's hard for me to say for sure. But looking at the BR's for the sc_req_item table, I do not see any async BRs, only before and after.
I do not see any async BRs on the sc_request or sc_task tables either.
I also tried changing the order to 50 and 200, but I still the same error.
Thanks again, you guys are extremely helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 10:24 PM
Can you tell me what happens if:
1. you change the Mihir's Br to async type and run your test?
2. check for the update()s in all the BR - go to All Business rules and in the filter set the condition to show all the BRs on sc_request, sc_req_item and sc_task tables with "update()" string in script. check for all the BRs returned.
I got 'unique key violation' error when i was trying to update() in business rules but due to multiple update()s running at the same time, system 'tends' to create another record with same sys_id - thus giving the error. If this is helpful to debug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2016 04:04 AM
Sumweet,
Changing it to run async instead of before did the trick, thank you very much.
This community is great, thank you all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 10:45 PM
Remove current.update(); from code and ur business rule is set as after update or before update it depends on you........ but dont do double update so it is showing you that error...BR of Mihir is perfect...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 09:17 AM
Hi Alexander,
Any specific reason to create custom requested for field?
There exist other ways as well to set the "requested for" on sc_request table as well. You can use the "Requested For" UI Macro
Catalog Category "Requested for" UI Macro