
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 12:15 PM
I have 2 inbound actions. The 2 emails come into the system at the same time. I need one to process first which creates the record and then the other one to update the record.
My first email that creates the record has an order of 15 and my update record has an order of 50 along with a gs.sleep of 5 minutes.
Both emails come in the inbox and neither process until the second one with the timer processes and of course the timer one is processing first which is not what I want.
Any ideas on how I can fix this issue.
Thanks,
Stacy
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 11:59 AM
I ended up creating a scheduled job that will look at the sys_email table and reprocess the particular events.
var gr = new GlideRecord('sys_email');
gr.addEncodedQuery('mailbox=received^subjectSTARTSWITHFW: SupportCentral Case Opened^instance=NULL^user_id=9673156edb58d8104c95550a48961958^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORsys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
gr.query();
while (gr.next()) {
var evt = new GlideRecord('sysevent');
evt.initialize();
evt.user_id = '9673156edb58d8104c95550a48961958';
evt.user_name = "RSI - BOL Integration";
evt.process_on = gs.nowDateTime();
evt.name = "email.read";
evt.parm1 = gr.sys_id;
evt.insert();
// gs.addInfoMessage(gs.getMessage('Event created to reprocess email "{0}"', Packages.org.apache.commons.lang.StringEscapeUtils.escapeXml(current.subject)));
if (gr.type == 'received-ignored') {
gr.type = "received";
gr.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 01:52 PM
Hi Stacy,
How does the second know to update the record created by email one? It might be an option to do an IF statement whereby we check if there is a record to be updated, if not we presume email 1 is being processed and instead we create a record in sys_trigger table.
var gdt = new GlideDateTime();
gdt.addSeconds(300); //Delay the trigger for 300 seconds to give the 1st email chance to create the record.
var trig = new GlideRecord('sys_trigger');
trig.initialize();
trig.name = 'Req #'+ gdt.getValue();
trig.next_action = gdt.getDisplayValue();
trig.job_id.setDisplayValue('RunScriptJob');
trig.trigger_type = '0';
trig.script = "var gr = new GlideRecord('incident');gr.newRecord();gr.short_description='test';gr.insert()";
trig.insert();
This is just an example. The script field I'd either pipe the data from the email into it to update the record or add the script logic to reprocess the email record. The latter wont cause an endless loop

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 08:32 AM
The first email contains all of the data to create my case. I do not have any delays on it as I want it to process as soon as it comes in.
My second email is an email that I just need to attach to the case, it is not changing fields.
In my script on the second email I start with a sleep of 1 minute, I then look to see if the case has been created I have an if statement that if it doesn't find the case to sleep 1 more minute and then update the case.
What I am experiencing now is both emails come in to the inbox at the exact same time. The first email isn't processing until the sleep is done on the second email so the second email never finds the case, so the sleep isn't working now.
I am not sure how I can use the sys_trigger to insert an email in to a case.
Thanks,
Stacy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 11:28 AM
Hi Stacey,
as emails process sequentially, using a gs.sleep will cause the entire email processing to pause, not just the record processing to which the sleep command was invoked.
If the email doesn't need to update the record and you just want to attach it:
var script = "var recordGR = new GlideRecord('incident'); recordGR.query(); if(recordGR.next()){var email = new GlideRecord('sys_email'); email.get('sys_id'," + sys_email.sys_id + "); email.setValue('instance'," + recordGR.sys_id + ");email.update();}";
var trig = new GlideRecord('sys_trigger');
trig.initialize();
trig.name = 'Req #' + email.subject;
trig.next_action.set = new GlideDateTime().addSeconds(120);
trig.job_id.setDisplayValue('RunScriptJob');
trig.trigger_type = '0';
trig.script = script;
trig.insert();
current.setAbortAction(true);
Will need to modify the initial gliderecorod (recordGR) to the search query to find the record you want the email to attach to.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 11:59 AM
I ended up creating a scheduled job that will look at the sys_email table and reprocess the particular events.
var gr = new GlideRecord('sys_email');
gr.addEncodedQuery('mailbox=received^subjectSTARTSWITHFW: SupportCentral Case Opened^instance=NULL^user_id=9673156edb58d8104c95550a48961958^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORsys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
gr.query();
while (gr.next()) {
var evt = new GlideRecord('sysevent');
evt.initialize();
evt.user_id = '9673156edb58d8104c95550a48961958';
evt.user_name = "RSI - BOL Integration";
evt.process_on = gs.nowDateTime();
evt.name = "email.read";
evt.parm1 = gr.sys_id;
evt.insert();
// gs.addInfoMessage(gs.getMessage('Event created to reprocess email "{0}"', Packages.org.apache.commons.lang.StringEscapeUtils.escapeXml(current.subject)));
if (gr.type == 'received-ignored') {
gr.type = "received";
gr.update();
}
}