Update Request Item with Inbound Email Action.

karthikbabu
Giga Expert

Hi All,

 

I am working on a requirement.

An email will be received by vendor (email subject doesn't consists of RE or FWD). The email subject consists of the RITM number as "XXX Quote Confirmation: Quote Ref. RITMnumber [EXTERNAL]". This should update the appropriate RITM with the attachment that is coming from the email. I have tried several methods from community but all solutions creates a new RITM instead of updating existing RITM with attachment. 

PLEASE NOTE THAT EMAIL SUBJECT DOESN'T CONSISTS OF "RE" OR "FWD".

Please suggest.

Thank you,

Karthik

8 REPLIES 8

Tony Chatfield1
Kilo Patron

Hi,

Your email subject doesn’t need to contain re or forward prefix, as you can\will create an inbound action that meets your requirements.

If the response does not contain a watermark from your instance, then you will need to script a glide lookup of the task you want to update via the task number in the email (as it's the only reference you have).

Probably something like
var my_number = a string function to get your task number from the email

// then make sure you have the correct value by logging the result - at least for testing.

gr = new GlideRecord('your task type');
gr.get('number', my_number);

 // if(gr)
//update your task with your email details eg

gr.your_task_field = values from your email;

gr.update();

//else

//manage the error condition if task number not found.

 

 You should ensure you have adequate filtering\controls set for your inbound action so that you are not just matching a task number in any email Eg match a known email source address – I would set up a dedicated address and then forward to snc.

Appreciate your response.

 

I tried as per your suggestion but id didn't worked.

find_real_file.png

I have the below script in the action.

 

"gs.include('validators');

if (current.getTableName() == "sc_req_item") {
//current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.comments = "reply from: " + email.origemail;

if (gs.hasRole("itil")) {
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;

if (email.body.priority != undefined && isNumeric(email.body.priority))
current.priority = email.body.priority;
}
//// script for copying attachment from email to RITM
var sourceSysID = email.sys_id;
var targetSysID = current.sys_id;
var copyAtt = new GlideSysAttachment();
copyAtt.copy('sys_email',sourceSysID, 'sc_req_item',targetSysID);
//// script for copying attachment from email to RITM

current.update();
}"

 

The action is creating a new call ticket when email subject has "FW:" and does nothing if email subject has "FWD:" or subject has "XXX Quote Confirmation: Quote #xxx/P.O. Ref. RITM0151193". Please suggest if anything wrong in my action.

 

Thanks you,

Karthik

Hi,

 You will need to work through your code and debug it line by line, to confirm what does\doesn’t function and why
The easiest way to do this is probably to write all your variables and any conditional results to the log (or at least include a log statement to ensure you successfully enter any condition).

 Your inbound action shows as a type of Reply, but you are wanting to process a FWD: email
Have you checked email properties to confirm that messages prefixed FWD: are treated as reply message?
OOB I suspect they are flagged as type forward.

I don’t think you need if (current.getTableName() == "sc_req_item")
as the inbound action target table is sc_req_item  and so this should always be true.

gs.hasRole("itil")
This probably prevents processing of your message if the email sender is not matched to a known user with ITIL license, is this the intention?

Your email body priority doesn’t ensure you value is valid, just that it is a number.
If you feel you need this validation\check then maybe
if (email.body.priority >= 1 && email.body.priority <= 5) // or your lowest value
also these may need to be strings not numbers?

Allen Andreas
Administrator
Administrator

Hello,

Please ensure your Inbound Action for this table is set as "Reply" ...not "New". Reply is not only used for a literal "reply" (meaning the subject like has RE...) but it means that if you're associating it to a record (which per your post...you are...) then it's a reply. This sounds like you have the type set as "New", which is not correct.

You do not need to do anything else special if the RITM number is within the subject line. ServiceNow will pick that up automatically.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!