Inbound Email Actions multiple update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 12:34 AM
Hi Experts
I have a really complicated issue.
I have created an inbound Email Action for a Time Card Approval Process.
this inbound Action is triggered when an approve email comes from a manager with Subject == approve.
The Target Table is Sys_User as my Notification Template must be on the Sys_user Table but the information that needs to be updated and approve is on the Time Card Table.
Now In my Inbound Action as I said Target is Sys_user and then in the script I GlideRecord Time card table with the fitler of the user that is requesting this approval.
The GlideRecord is working and giving me the correct data.
Now I just need to approve each record (changing state from Submitted to Approved) in the Time card table.
e.g. User A have 3 Time Records submitted, the manager gets an email with all 3 records and he approves via email. the Inbound action started and gliderecord filtering the user and in the while statement I can log all 3 data and see them but when I say gr.update(); to update my state, it only update one record. even it is running threw all 3.
Does anyone have an idea what is running wrong?
if (email.subject.indexOf("approve") >= 0) {
var gr = new GlideRecord('time_card');
gr.addQuery('user', current.sys_id);
gr.addQuery('state', 'Submitted');
gr.query();
while(gr.next()) {
gs.log('TIME INBOUND APPROVED for CURRENT USER: ' + current.name);
gr.state = "Approved";
gr.update();
}
}
thanks
Elias
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 02:58 AM
Finaly found the issue and solved it,
As I assumed it was a business rule that is updating the task number at the same time as I am running my script with updating states and somehow it is conflicting with it., I just deactivate it and it is now working.
thanks for all your help.
Elias
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 05:33 AM
Hi
this is the Business Rule that causing all the issues: "Create expense from approved time card"
it is an OOB from serviceNow and I am not sure what is really conflicting. The problem I need this Business Rule to create an Expense Line after a time record has been created.
Elias
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 06:04 AM
Elias,
To be honnest, I don"t know why it is conflicting, since the OOTB business rules is calling the script include TaskRateProcessor which calculated the rates and other stuff.
If you deactivate that business rules, everything works as expected ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 06:10 AM
Yes if I deactivate this BR everything works as expected except it wont create any Expense Line.
and the time record will change to Approve only and not Processed.
After a long research I am assuming that the conflict is because I am running a multiple update script to update a list record with multiple time records and this BR is only using Current one.
So I think is that the BR will run and use only the current record that it has and update it, all the rest will ignore.
This is the conflict but I do not know now how to simulate the Update Button when I select all records on a list view.
I have the idea to create a loop in my aupdate script and count the records and run the script as long as I have records to do.
Elias
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 08:24 AM
Be aware that this logic may have an impact on the performance,
On my side, i will take a deep look and will comaback to you with a new solution