how to trigger a email notification based on choice selected in the Request field of item?

Deepika61
Tera Contributor

Hi All ,

Actually we have one catalog item in that there is choice field "request " with choices Add, Mod, Return, , based on the choice selected , then different variable sets are appear and flow is different for each choice, Here if he select "Add" then corresponding flow will follow, if he selects Return then corresponding flow will follow, So end of the flow we need to trigger one email notification  based on the the request like if he selects  "Add", then end of that flow we need to trigger that email notification with  that fields

 

So here i need to achieve all request in single email notification only, so for that in the flow itself i have create one action to trigger an event , how can i differentiate those in single email notificatio\n

 

Please help me to achieve this

Thanks

Deepika

5 REPLIES 5

Community Alums
Not applicable

Hi @Deepika61 ,

Use an advanced condition to send a notification based on the current email record, changing field values, or system properties.

To send a notification using an advanced condition, you can:
  • Call a function that returns a value, or
  • Set the global variable answer using a script
For example, in the following code, you call a function to prevent the system from sending an email notification if the sender of a self-service request is a member of the XYZ group:
(function() {
  var groupMember = gs.getUser();
  return !groupMember.isMemberOf('XYZ');
})();

Alternatively, you can script the same advanced condition by using the answer variable:

var groupMember = gs.getUser();
  if(groupMember.isMemberOf('XYZ')){
    answer = false;
  } else {
    answer = true;
  };

Note that the script must set the answer variable to true to send the notification. If you script no conditionals, the value of answer is equal to the last value that you set for the variable.

You can add a script-based condition in the Advanced condition field by configuring the Email Notification form and adding the field. You can access the field in the Advanced view without configuring the form.

The advanced condition script uses the following business rule global variables:
  • current: contains the current record from the table to which the notification is linked.
  • event: contains the event that triggered the notification.

 

Pavankumar_1
Mega Patron

Hi @Deepika61 ,

you can create notification and set send when as Triggered in When to Send tab and use to on the flow last action like if Choice is  If choice is Add use Send Notification action and select your notification.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Hi Pavan,

Thanks for the response

Actually i have created one action for trigger event in flow from that event is triggered, So now my requirement was that i need to send a notification to user based upon request type like if it is Add i need to send few details like ip , host in table format and address , name these are below, like wise if request type is mod then i need to send a notification with details  ip , host in table format and category , device below, same for Request type return also,

So there all are i need to achieve through single notification only, please provide me the sample script

Below screenshot is my trigger action in flow

 

Thanks 

Deepika

Hi @Deepika61 ,

If I understood correctly you need to send the mail based on different variable details on single notification. Try below

1. Create the notification on sc_req_item table and on condition select Item is your catalog item name and use advanced condition it will be available n advanced view

var val = current.variables.request;//pass your variable name
if (val == '2' || val=='1') {//you can change the if logic as per your choices
    answer = true;
}

Screenshot (721).png

2. To display mail body different based on variables you need to use mail script and pass it on body.

 (function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var val = current.variables.request;
    if (val == '2') {
        template.print("Request Type is " + val); //here pass your variable name
        template.print('<br>'); //break the line
        template.print("Notes is " + current.variables.notes); //here pass your variable name

    } else if (val == '1') {
        template.print("Request Type is " + val); //here pass your variable name
        template.print('<br>'); //break the line
        template.print("Desciption  is " + current.variables.description); //here pass your variable name
    } else {
        template.print("Request Type is " + val);
    }

})(current, template, email, email_action, event);

Screenshot:

Screenshot (723).png

Email Body:

 use  mail script on mail body.

${mail_script:mailscript name}

Ex:

${mail_script:test_catalog_item_variables}

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar