- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2019 02:01 AM
Actually my requirement if a provider send a new email with existing incident number, its updating the existing incident.
am tried in different ways am not able to do,it creating a new incident
IT is possible? with a new email subject contains existing number we can update the same incident ?
Can Someone Help me on this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2019 06:51 AM
Dude. i don't even know where to start with this!
The code you've posted that is apparently working doesn't look likely to work at all. Can you check the email logs of some inbound messages from your provider that you think were processed by this inbound action and just confirm which inbound action actually picked them up?
1. You're getting the indexOf('INC') in you mcn1 variable but then making a substring of that index+1 so you'll end up with 'NC12345678'
2. You're then making an incNum variable with substrings of an inc variable that doesn't exist
3. You're also using a regex to find a string of 7 numbers
4. You're then running a glide record where you are trying to find a record where the number field matches the content of 3 different variables that you've populated with different values. THIS WILL NEVER RETURN ANY RESULTS!
Say the number field is INC12345678, your mcn1 variable will be NC12345678, your incNum variable will be undefined and your matchedNumber variable will be 1234567. None of them would work on their own and they certainly won't work when your query requires all of them to match the number field!
You can try the code below but without knowing your instance or being able to troubleshoot myself i'm kinda shooting in the dark.
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var sub = email.subject;
var index = sub.indexOf('INC');
var mcn1 = sub.substring(index,index+10);
gs.log('this is the inc ref: ' + mcn1);
var index1 = sub.indexOf('[OS');
var index2 = sub.indexOf(']');
var mcn = sub.substring(index1,index2+1);
gs.log('this is the provider ref: ' + mcn);
var gr = new GlideRecord('incident');
gr.addQuery('number',mcn1);
gr.query();
if(gr.next()){
gs.log("Test8 inside if"+gr.number+"mission-->"+gr.u_external_ticket_reference);
gr.comments="UPDATE FROM OPEN SYSTEM ";
gr.u_external_ticket_reference=mcn;
gr.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
gr.update();
}
}
})(current, event, email, logger, classifier);
Write exactly that and let me know what the gs.log's come back as maybe i can help further, we'll see!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2019 10:52 PM
Tbh the condition on the create incident rule shouldn't be required, as long as the rule running the code i provided is put at a lower order than the create incident it should stop processing further rules once it's done mine thanks to the event.state = 'stop_processing'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 05:51 AM
Have you tried this approach mentioned above? If it did not work, first try to disable the inbound action "create new incident" and then check and see if the update is working correctly or not.
If update is working fine, then the only problem to solve is changing the order of create incident as suggested by David or adding an condition as suggested by me above in create incident. Either way, that should solve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 05:47 AM
Still its creates a new incident,
when the provider gives a reply to the snow without watermark and without re:,subject line contains the incident number,it updates the same record,
But provider sends a new email with Existing incident it does nt updates the existing.
still am struggling on these topic.
Can u help me what i need to change,i tried in possible as you said.
Regards,
Chinna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 05:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 06:27 AM
Hi David,
I tried as u suggested but still it creates a new incident
PFA,the screen looks like as what u said look at attached screenshot and i can use this script only,where i need to change exactly,
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
gs.include('validators');
var sub=email.subject;
var index3=sub.indexOf('INC');
var incNum= sub.substring(inc,inc+10);
var numberPattern = "/[0-9]{7}/";
var reg = new SNC.Regex(numberPattern);
var matchedNumber = reg.match(email.subject);
if (JSUtil.notNil(matchedNumber)){
var gr = new GlideRecord("incident");
//Update this with your old ticket number field column name
gr.addQuery('number',incNum);
gr.addQuery("number", matchedNumber);
gr.query();
if(gr.next()) {
if(email.subject.toLowerCase().indexOf("worknotes") >= 0){
gr.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
gr.update();
//event.state="stop_processing";
}
else{
gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
gr.update();
//event.state="stop_processing";
gr.update();
}
}
// Implement email action here
}
event.state="stop_processing";
})(current, event, email, logger, classifier);