Script in Workflow Notification

stevenm
Kilo Guru

My users would like an email notification come out of a workflow.   That's all fine and dandy.   However, they would like the body of the email to be based on some of the values entered on the service request.   For instance if a field says approver they would like the email text to reflect approver otherwise have it reflect non-approver.   Will mail_script work within a Workflow Notification?   I'm not getting any output from the if statement below.

Capture.JPG

1 ACCEPTED SOLUTION

stevenm
Kilo Guru

This is really old and I don't recall why my question.  Thanks for replying.  I guess I better mark it closed.

View solution in original post

11 REPLIES 11

ChanakyaMekala
Kilo Guru

In workflow activities if you want to use variables of catalog item, you need to dot walk using "current" object use ${current.variables.<variable_name>}

 

Ex:

Request Type: ::::> ${current.variables.dialer_req_type}

Thanks for the dot walking advice.. do you have any recommendations if this doesn't pull it up the variable needed... 

I am trying to pull Employee Name from the Request so I'm using 

${current.variables.employee_name} and it's not working. 

Hey Lenna,

I know this post is old, but you do not need curly brackets or the dollar sign in the mail script.

Try the below code.

 

<mail_script>

if(current.variables.employee_name == 'xxxxx')

{

template.print('Whatever verbiage is needed');

}

</mail_script>

 

Derek17
Tera Contributor

Hey Steven,

I know this post is a bit old, but if you decide to use a mail script in a workflow notification you do not need curly brackets or the dollar sign. 

Please try the below code when using a mail script.

 

<mail_script>

if(current.variables.g_Access_Needed == 'Approver')

{

     template.print('Approver & Editor');

}

else

{

     template.print('Not Approver');

}

</mail_script>

Salah2
Tera Contributor

Hey Derek,

without much success, I tried to modify the mail script [request.itil.approve.role_script_1] below so that the Request Approval notification only displays only selected variables.  Current, the notification is displaying every available variable.  If you are able, could you please help? Thanks.  

 

template.print("Summary of Requested items:\n");

var item = new GlideRecord("sc_req_item");

item.addQuery("sys_id", current.sysapproval);

item.query();

while(item.next()) { 
      template.print(item.number + ":  " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at " + item.price.getDisplayValue() + " each \n");
      template.print("    Options:\n");

      var keys = new Array();

      var set = new GlideappVariablePoolQuestionSet();

      set.setRequestID(item.sys_id); 

      set.load();

      var vs = set.getFlatQuestions();

      for (var i=0; i < vs.size(); i++) {

        if(vs.get(i).getDisplayValue() != '') {

          template.space(4); 

          template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
                    }
               }
         }