- 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 08:40 AM
Hi Alexander,
I think you missed to add the query- grRITM.addQuery('request', current.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 08:55 AM
Hey Manoj, thanks for the reply.
I took that out thinking I didn't need it anymore since I'm no longer dealing with the Request table. I'm only with the Requested Item table.
I tried it both ways and neither worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 09:12 AM
Can you tell me the conditions you have set from existing to now ? Before or After and on update or insert ? Do you want to do this for all the request items in the sc_req_item which are in the table ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2016 12:41 PM
Hey Manoj,
I need a BR that pulls the user from a variable on a catalog item and sets the u_requested_for field on the sc_req_item table to that user.
Mihir's BR worked, but I'm getting some error after ordering the RITM and I don't see any errors on that BR running.
Unique Key violation detected by database (Duplicate entry 'ef1665ba2bee1200116ad1cc27da15b7' for key 'PRIMARY')
Unique Key violation detected by database (Duplicate entry 'a31665ba2bee1200116ad1cc27da15b9' for key 'PRIMARY')