Customize Approval Request notification

pathat
Kilo Expert

Hello.

I would like to customize the OOB Approval Request notification that you get when you use the OOB Approval-User notification in the workflow designer.

How do I customize this core component in the workflow designer? I assume SN allows you to create a custom notification workflow activity and make it available in the workflow designer?

9 REPLIES 9

Steven Young
Tera Guru

we just created multiple appoval notifications and did a filter to select one.
find_real_file.png



I dont know how many approvals you are dealing with.   we are upwards of 45.  



However.   We are tying each approval to the Request Item form.


find_real_file.png


Each of these fields are on the Request Item form.   When we mark a request Item Inactive, the associated referenced items also are inactivated.


(sneaky here, but we create these email notification from a script with just 2 clicks.   )   Saves a TON of time.



We have deactivated the Generic Approval.


and we use custom approvals similar to this


approval.png



And it's all done automatically now.   i used to hate creating this.   and script to create this automatically was a pain,   but worth it in the end.


Steven,


how are you including the value of the variables from your Catalog Item in the body of the approval notification?



I've found a few suggestions but so far nothing seems to be working for me.



Most recent suggestion I found was to use template.print in order to pull them but when using script below, the notification message simply spits out the code as seen below vs. actually grabbing any of the variables from my form



template.print("Summary of Requested Item: \n"); template.print("" + gs.getProperty("glide.servlet.uri") + ": \n");


var desc = current.sysapproval.short_description;


var number = current.sysapproval.number;



template.print("\n");


template.print("Request Item " + number + ":" + desc + " \n");


for (key in current.sysapproval.variables) {


var v = current.sysapproval.variables[key];


if(v.getGlideObject().getQuestion().getLabel() != '') {


if(v.getDisplayValue() != 'false'){


if(v.getDisplayValue() != ''){


if(v != "" && v != null && typeof(v) != "undefined") {


template.space(4);


template.print('' + v.getGlideObject().getQuestion().getLabel() + ": " + v.getDisplayValue() + " \n");


}



Thanks,


Andrew


Found the answer I needed here:   SC_REQ_ITEM Approval Emails


What i've done is created a Business rule on the Request Item form.   Actually 5 business rules.


On the Request Item form, i added some fields that will link this request item to any approval email/script/templates.


sn1.png



So


1.   all fields are hidden until Create Approval Emails   is selected.


2.   then decide if you want a script or a template.


3.   select which approvals you want.


          a.   We have an approval email,


          b.   a Reminder Email (sent by scheduled job after 3 days of being open and not approved)


          c.   a resend email.   This can be manually sent by going to the approval and hitting a button for resending.


This allows us to customize our approval emails how our organization wants.



4.   everything on the right is blank.   Once i save this form, the Business rules will create the email script first.   It will pull all the Active Variables on the form and create a no-touch script, with If() statements.   So that if a variable is empty, it will not show in the approval email.


5.   it will then generate the email notifications.


6   after each script/template   and email notification is created, it will then update this form with the values as seen.


7.   the last thing is you see a regenerate script check box.   Previously if we added variables to the form, we would have to manually add that to the script or template.


            now,   after we add variables, we simply click that check box,   save the form.   the BR will query all variables and regenerate that script with no further action needed.   next time the related emails are generated, they will have the latest variables included.


8   Lastly,   When this form is inactivated,   another BR will query the 4 fields.   the script and 3 emails, and will mark those inactive so they dont show in queries.     Can you tell i'm sick of manually creating the same junk over and over????



the Email notification is very simple.


sn2.png



It generates EVERYTHING we need,   from the name, to the condition to the message_html as you can see above.


The mail scripts in here have already been created previously.   all of the mail scripts are the same across all of our   approvals.   The only different is the 3rd script down.


That is the one that is auto generated from the BR as stated earlier.   This is where the script inserts the template if the template was selected.



The


mail_script:For_The_Administrator


runs and tells us what email notification sent the email, what template was used (if any) who the notification was sent to and what the ticket number is that generated the email.   This is being added to every email we send.   Currently it's on about 70%   and it's made life much easier.   If people want to turn off the notification, they have the email notification name to turn it off.


find_real_file.png



This saves us SOOOO much time from having to manually create notifications, and look for notification when someone fwd's us an email asking about it.



So the Script in the email notification pulling the variables,   the query is as so.


(function runMailScript(current, template, email, email_action, event) {



  // Add your code here


  // ${mail_script:Application Package request form}     Mail script name for use in the Email Notifications



  var item = new GlideRecord('sc_req_item');


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


  item.query();


  if (item.next()) {



  if(!item.variables.prf_package_name.nil()){


  template.print("Application Package   <font color = '#000080'><b>" + item.variables.prf_package_name+"</font></b>\n\n");


  }



  if(!item.variables.prf_current_choice.nil()){


  template.print("Is the Software Currently Listed?   <font color = '#000080'><b>" + item.variables.prf_current_choice.getDisplayValue()+"</font></b>\n");


  }




The script continues past that, but that is our beginning.


We do, do if statements because it cleans up the notifications a TON.   if you have a form with 400 variables, and only 30 are mandatory for the type of request,   we dont want 400 variables in the email.





Ok,   so let me know if this makes sense, and i you have any problems.


maybe I missed this, but how do you trigger the notifications to be sent? In order to get to the filter approval for.requested item.item you have to change the table on the notification to requested item. Then standard approval emails via workflow won't kick off because they only kick off on the sysapproval_approver table.