- 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 05:39 AM - edited 05-05-2023 05:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2023 06:51 AM
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";
}
- 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 10:55 AM
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.