The CreatorCon Call for Content is officially open! Get started here.

use random variable in email notification

Bradley Bush
Mega Sage

Hi, I have a custom notification that goes out to the "requested for" when the request is closed. In the request, seven variables are displayed one at a time based on another variable selection. The displayed variables are controlled by catalog UI policies and are only viewable on tasks. I need to have that random variable captured by the notification and sent to the "requested for" once the request is closed. Any help would be great, thank you.

Notification message:

BradleyBush_0-1713476459558.png

"Please select your MUV access." is a select box with seven options viewable all.

"Please select the correct AD group based on access requested/given:" is a label with seven checkboxes only viewable to one group on the task level.

BradleyBush_1-1713476542728.png

 

1 ACCEPTED SOLUTION

@Bradley Bush 

 

Try with below logic inside the mail script :

 

var ritmGr = new GlideRecord('sc_req_item');
    ritmGr.addQuery('sys_id', current.sys_id);
    ritmGr.query();
    if (ritmGr.next()) {
var num1 = ritmGr.variables.muv_selectbox_access.getDisplayValue();
template.print("test: "+num1);
}

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

AshishKM
Kilo Patron
Kilo Patron

Hi @Bradley Bush , 

You can write email script and reach the variables from RITM and prepare email body output.

 

Browse some of existing email script for reference.

AshishKMishra_0-1713478715707.png

 

 

-Thanks,
AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Amit Verma
Kilo Patron
Kilo Patron

Hi @Bradley Bush 

 

You can access the RITM variables via Email Scripts and call them inside your notification to render the variable values. Refer below post :

https://www.servicenow.com/community/developer-blog/how-to-populate-catalog-item-variables-on-notifi...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Bradley Bush
Mega Sage

Hi, thank you Ashish and Amit for the helpful script reference. I did write a script and can get the "text" to display in the notification, the variable will not display though. I tried a few different ways and checked the HTML for the notification, but still no success. Any script help would be great, I seem to be stuck for now.

 

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

    // Add your code here
    var num1 = current.variables.muv_selectbox_access.getdisplayvalue();

		template.print("test: "+num1);

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

 

After this runs I get "You have been granted test: undefined.
thank you

@Bradley Bush 

 

Try with below logic inside the mail script :

 

var ritmGr = new GlideRecord('sc_req_item');
    ritmGr.addQuery('sys_id', current.sys_id);
    ritmGr.query();
    if (ritmGr.next()) {
var num1 = ritmGr.variables.muv_selectbox_access.getDisplayValue();
template.print("test: "+num1);
}

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.