- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2023 05:34 AM - edited 01-26-2024 08:40 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2023 07:13 AM - edited 05-05-2023 07:14 AM
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2023 02:02 PM
Hi Steven! Thanks so much I was able to get the code working below.
gs.info("The current source " + current.source);
if (current.source == "email" || current.update_email_update == "update_received"); {
gs.info("INSIDE IF STATEMENT");
current.u_email_update = "Update Received";
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2023 10:08 AM
Great to hear! Please mark my response as helpful and correct if you can.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven