- 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-30-2019 12:26 AM
OK, so you should be using RegExp instead of SNC.regex, you still have the incNumber variable in there even though it's not being used and you have 2 query lines in your glide record matching the same field but to different values, this will obviously never return any results as the same field can never match 2 different things!
var reg = new SNC.Regex(numberPattern); //you should be using RegExp
var matchedNumber = reg.match(email.subject);
var incNum= sub.substring(inc,inc+10); //this is no longer needed if you're using regex
if (JSUtil.notNil(matchedNumber)) { //you don't need this, you can do the query in the glide record
var incidentRec = new GlideRecord("incident");
incidentRec.addQuery("number", matchedNumber);
//incidentRec.addQuery('number',incNum); //you can't have 2 different queries on the same field matching on different things
incidentRec.query();
You seem to be matching on a reference of ##12345##, this doesn't look like the number format of a service now incident. What is this reference?
The script below will find that reference in a subject line and search for any related incidents but the condition on the inbound action is looking for 'INC' so if your ticket reference is ##12345## it's not going to match that condition
gs.include('validators');
var regex = new RegExp(/#{2}[0-9]{5}#{2}/);
var incNumber = regex.exec(email.subject);
var gr = new GlideRecord('incident');
gr.addQuery('number', incNumber);
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";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2019 06:07 AM
Hi David,
still am facing a issue,
servicenow sends a notification to the provider,provider gives a reply without RE: prefix and without watermark am using this below code its works fine.
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var sub=email.subject;
var index1=sub.indexOf('[OS');
var index2=sub.indexOf(']');
var mcn=sub.substring(index1,index2+1);
var index3=sub.indexOf('[INC');
var mcn1=sub.substring(index3+1,index3+11);
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');
gr.addQuery('number',mcn1);
gr.addQuery("number", matchedNumber);
gr.addQuery('number',incNum);
gr.query();
if(gr.next()){
gs.log("Test8 SUB-->"+sub);
gs.log("Test8 mcn1-->"+mcn1);
gs.log("Test8 MCN"+mcn);
gs.log("Test8 inside if"+gr.number+"mission-->"+gr.u_external_ticket_reference);
gs.log("Test7 both are same");
gr.comments="UPDATE FROM OPEN SYSTEM ";
gr.u_external_ticket_reference=mcn;
// gr.work_notes="testing 123";
gr.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
gr.update();
}
}
})(current, event, email, logger, classifier);
But my problem if provider sends to new email with provider number and incident number in the subject like [OS-342567] INC3425626 needs to update the same incident.
i tried your code also its not working for me.
This is existing code for update the incidents from my provider(Open Systems)
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var sub=email.subject;
var incnum=sub.slice(0,10);
var index1=sub.indexOf('[OS');
var index2=sub.indexOf(']');
var mcn=sub.substring(index1,index2+1);
var index3=sub.indexOf('[INC');
var mcn1=sub.substring(index3+1,index3+11);
gs.log("Test8 SUB-->"+sub);
gs.log("Test8 mcn1-->"+mcn1);
gs.log("Test8 MCN"+mcn);
var gr=new GlideRecord('incident');
// gr.addQuery('u_mission_control_number',mcn);
gr.addQuery('number',mcn1);
gr.query();
if(gr.next()){
gs.log("Test8 inside if"+gr.number+"mission-->"+gr.u_external_ticket_reference);
gs.log("Test7 both are same");
gr.comments="UPDATE FROM OPEN SYSTEM ";
gr.u_external_ticket_reference=mcn;
// gr.work_notes="testing 123";
gr.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
gr.update();
}
})(current, event, email, logger, classifier);
where i need to change the script in this existing one,
i tried with below code but its not working
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var sub=email.subject;
var index1=sub.indexOf('[OS');
var index2=sub.indexOf(']');
var mcn=sub.substring(index1,index2+1);
var index3=sub.indexOf('[INC');
var mcn1=sub.substring(index3+1,index3+11);
var incNum= sub.substring(inc,inc+10);
var numberPattern = "/[0-9]{7}/";
var reg = new SNC.Regex(numberPattern);
var matchedNumber = reg.match(email.subject);
var gr= new GlideRecord('incident');
gr.addQuery('number',mcn1);
gr.addQuery("number", matchedNumber);
gr.addQuery('number',incNum);
gr.query();
if(gr.next()){
gs.log("Test8 SUB-->"+sub);
gs.log("Test8 mcn1-->"+mcn1);
gs.log("Test8 MCN"+mcn);
gs.log("Test8 inside if"+gr.number+"mission-->"+gr.u_external_ticket_reference);
gs.log("Test7 both are same");
gr.comments="UPDATE FROM OPEN SYSTEM ";
gr.u_external_ticket_reference=mcn;
// gr.work_notes="testing 123";
gr.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
gr.update();
}
}
})(current, event, email, logger, classifier);
can u please help me on this
Regards,
Chinna
- 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
‎02-05-2019 03:58 AM
Thanks you so much david, it works fine