
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 08:12 AM
Hello SN Comm,
I have an Inbound Email Action to update an HR Case when it is in Pending Customer state.
When to run tab:
Type: Reply
Conditions: (Currently nothing)
Actions tab:
Field actions: State TO Work in Progress
Script:
gs.include('validators');
// Pending Customer Case moves to WIP from incoming email by customer
if (current.getTableName() == "hr_case" && current.state == 😎 {
current.work_notes= "reply from: " + email.origemail + "\n\n" + email.body_text;
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
}
***************************************
Want/need:
I want to have the ability for this Inbound Action to trigger ONLY when the email reply is someone attached to the Case (Example: if the reply coming in is the Requested For/ Caller)
I do NOT want this Inbound Email action to trigger if someone not working on the Case emails in to it (Example: if the reply coming in is a Manager of the group that the Case is assigned to, etc).
Mainly because when the Case state is in Pending Customer, the Customer is the one that needs to provide information. This is why I would like the Inbound Action to be triggered when the Customer emails back in to the Case.
Does this request make sense? I looked through the Conditions under When to run tab and none available seem to be what I need for this.
Hopefully I have explained this well enough to receive some help.
Any help is greatly appreciated!
Cheers,
-Rob
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 06:38 AM
Thanks everyone for your help on this!
I was able to configure the script to how I needed it, here is what I have:
gs.include('validators');
var userAddr = email.from;
gs.log("User email: " + userAddr);
// Update work notes regardless of who sends email
current.work_notes= "reply from: " + email.origemail + "\n\n" + email.body_text;
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
// Pending Customer Case moves to WIP from incoming email by requestor/requested for
if (current.getTableName() == "hr_case" && current.state == 8 && (current.caller.email == userAddr || current.opened_for.email == userAddr)) {
current.state = 18;
}
// Update case
current.update();
Inbound action records the incoming emails to Case Activity, all while NOT changing the State back to WIP UNLESS the email comes from Requestor/Requested For.
Thanks again for the help here!!
Cheers,
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 08:17 AM
You can use a more advanced condition in the script itself. Check to see if the email from is the current caller/opened_for/opened_by, and if it isn't you can 'return' or stop the script from proceeding further.
Take a look at the 'Update Approval Request' inbound action, you may be able to get a good example form there. It may require an additional GlideRecord query, but you should be able to handle this in the script.
Cheers,
Tim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 08:25 AM
Thanks Tim,
I will check this out and see what I can accomplish using 'Update Approval Request' as a reference.
Appreciate the information!
Cheers,
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 08:40 AM
No worries!
Check the 'isValidUser()' function in that approval inbound action, something like that should work for what you need.
Cheers,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 09:37 AM
You could do this by using a Script Include triggered by a Business Rule.
The Business Rule would trigger when the work note field on the case changes and validate who made the comment and take actions based on it.
I would assume here that you already have inbound actions dealing with all reply emails for the specific table and update them with a work note. If not the solution won't work.
Example:
In this example I have a Business Rule that will check if the user writing the work note is the assigned to person or is part of the assignment group. If not, I'll continue to run the Business Rule.
Business Rule
Condition: State is Pending Customer AND Work notes changes
(function executeRule(current, previous /*null when async*/) {
//Call the Script Include and Function
var runInboundAction = new yourUtils().yourFunctionName(current.sys_updated_by,current.assigned_to,current.assignment_group);
//If updated wasn't made by someone in the assignment group, proceed and run the code
if(runInboundAction){
//Insert the code you want to be run here
current.setValue('state', your_state_value);
}
})(current, previous);
The reason to why I don't add the validation by the Script Include to the Condition field on advanced tab is because it would evaluate every time there is an update to the case (seems like this condition and the condition on When to run triggers simultaneously).
Script Include
var yourUtils = Class.create();
yourUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
yourFunctionName: function(updatedBy, assignedTo, assignmentGroup){
var udb = '';
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', updatedBy);
gr.query();
if (gr.next()) {
udb = gr.sys_id;
//If updated by is same as assigned to, nothing should happen
if(udb == assignedTo)
return false;
}
var gr2 = new GlideRecord('sys_user_grmember');
gr2.addQuery('user', udb);
gr2.addQuery('group', assignmentGroup);
gr2.query();
//If updated by is part of assignment group, nothing should happen
if (gr2.getRowCount() > 0) {
return false;
}
//If updated by is not part of assignment group, process with business rule
else
return true;
},
type: 'yourUtils'
});
You would have to add all your conditions into the script include, in this example it'll only check if the person updating is part of assignment group or not.