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 12:38 AM
try this
if (email.subject.toLowerCase().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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 12:43 AM
Just an update:
I have now noticed the issue has nothing to do with the Inbound Action.
I just ran this script also on the Scripts Background an I am getting the same issue, it is only updating one record.
@Farukh I have tried your script but unfortunately it didnt work, it didnt update anything.
Thanks
Elias
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 12:58 AM
Use this line in while loop to check how many records you are grtting after query: gs.log(gr.getRowCount(),'Records')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 01:02 AM
I am getting 3.
I am assuming that has maybe to do with some business rules runs on the time card table and touching only one record somehow.
I will have to check my BRs.
BTW I have tried on the list view to select all 3 records and click on the update button and it approves all 3 at once. so why it doesnt with a script?
Elias