Email Received field on Incident form

cdavis22
Tera Contributor

Good Morning,

 

I am reaching out for help with the code below. I have been asked to create a custom field on the Incident form that changes to "update received" when incident receives an email. The field is automatically on update clear & when someone replies to the incident notification it should change to "Update Received". My Business rule below is not automatically updating the form. Please see code & BR, also the the field did not update with or without the filter condition so I am assuming it is the code. 

 

Custom field:

 

 

 

 

// Check if the update came from an email
if (current.source == "email" || current.source == "Inbound email") {

// Set the value of the Update Status field to "Update received"
current.u_email_update = "Update received";
}

})(current, previous);

 

1 ACCEPTED SOLUTION

The select box is fine, but you need to be using the value of the fields versus the labels.  So right click the "Email Update" field and click Show Choice List...you will then see something like this:

StevenParker_0-1683295659893.png

You want to use the Value column in your script.

 

I also just noticed your Business Rule needs to have "Update" checked because you want it to run when an Update (inbound email) is received.  Having insert checked means that the business rule will only run just before the Incident record is submitted to the table.

 

As for the script, it would look something like this:

I am assuming the Column Names are correct in your script (source and u_email_update).  Any custom field you created on the table would have u_ in front of it (Right click a column header in the Incident list view, configure table, and look at the Column Names):

 

gs.info("The current source " + current.source);
if (current.source == "email" || current.source == "inbound_email") {
gs.info("INSIDE IF STATEMENT");
current.u_email_update = "update_received";
}

 

 Then make sure you are using the Value of the choice inside the quotes.  Not the Label that you see in the choice box.  Sometimes they are the same if you created them that way, but most times they are not.  

System Logs -> Script Log Statements is where you can see the gs.info logs and check if you are making it inside the if and the source values from the other log.


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

View solution in original post

6 REPLIES 6

Steven Parker
Giga Sage

Is u_email_update a select box or a list collector?

 

Populating a List Collector from a script would required using a sys_id.  So in your code you wouldn't use "Update received", you would use a sys_id.  It would look like this:

 

 

current.u_email_update = 'sys_id of Update Received';

 

 

Your IF Statements for the source make sure those are the correct values for the field.  

 

Put some logging in there too and make sure you are making it inside your IF statement.

gs.info("INSIDE IF STATEMENT");

Then you can check the script log statements table and make sure you are getting where you need to be.  You can check source values as well if needed by logging those too.

gs.info("The current source " + current.source);

 


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Hi Steven! The update email field is a choice? Would a check box be better?

 

Also Please see below, I'm extremely new to coding.

gs.info("INSIDE IF STATEMENT");

gs.info("The current source " + current.source);

if (current.source == "email" || current.source == "Inbound email") {

current.email_update_status = "Update received";

}

The select box is fine, but you need to be using the value of the fields versus the labels.  So right click the "Email Update" field and click Show Choice List...you will then see something like this:

StevenParker_0-1683295659893.png

You want to use the Value column in your script.

 

I also just noticed your Business Rule needs to have "Update" checked because you want it to run when an Update (inbound email) is received.  Having insert checked means that the business rule will only run just before the Incident record is submitted to the table.

 

As for the script, it would look something like this:

I am assuming the Column Names are correct in your script (source and u_email_update).  Any custom field you created on the table would have u_ in front of it (Right click a column header in the Incident list view, configure table, and look at the Column Names):

 

gs.info("The current source " + current.source);
if (current.source == "email" || current.source == "inbound_email") {
gs.info("INSIDE IF STATEMENT");
current.u_email_update = "update_received";
}

 

 Then make sure you are using the Value of the choice inside the quotes.  Not the Label that you see in the choice box.  Sometimes they are the same if you created them that way, but most times they are not.  

System Logs -> Script Log Statements is where you can see the gs.info logs and check if you are making it inside the if and the source values from the other log.


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Hi,

 

I am not sure what's not working on my end. I assigned the ticket to myself & then went on to reply to the email. Nothing changed on the from. I tried both using the sys_id & The value name which is the same as the label name.

cdavis22_0-1683309170937.pngcdavis22_1-1683309247637.pngcdavis22_2-1683309299824.png