Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Workflow and notification

nameisnani
Mega Sage

Hi Team ,

 

We have an requirement that ,

 

In the catalog for we have line manager , 

 

Once Line manager approves , we need to send email to xyz@gmail.com , After that two parallel SC task has to be triggered .

 

nameisnani_1-1718848586700.png

 

 

 

This is catalog form 

nameisnani_2-1718848686514.png

 

 The challenge i am facing in notification 

 

Requirment is 

 

Body of the notification 

 

Subject: <Short description>

"A lost or stolen device has been reported by" <Requested For>
The device was lost or stolen on <Date item was Lost/Stolen>
[Blank Line]
"Description:"
<Description>

 

 

nameisnani_3-1718848807608.png

 

How should i bring catalog variables in the notification , in the right hand side i can't find catalog variables .

 

can anyone please help me here , on this requirements

 

Thanks in advance  

2 ACCEPTED SOLUTIONS

SN_Learn
Kilo Patron
Kilo Patron

Hi @nameisnani ,

 

You have to utilize notification email scripts to pull out the variables of the catalog item.

Create new record in notification email script as below:

SN_Learn_0-1718857107122.png

 

Then call the above script in notification as below:

SN_Learn_1-1718857167572.png

 

${mail_script:scriptName}

 

Mark this as Helpful / Accept the Solution if this clears your issue

 

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

@nameisnani 

you are using the wrong syntax to get variable value

the correct syntax is current.variables.variableName

update as this

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

    var requester = current.variables.requested_for.getDisplayValue();
    var date = current.variables.date_item_was_lost_stolen.getDisplayValue();

    email.setSubject(current.variables.short_description_1);
    template.print("<p>A lost or stolen device has been reported by " + requester);
    template.print("<p>The device was lost or stolen on " + date);
    template.print("<br />");
    template.print("Description:" + current.variables.description_1);



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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

SN_Learn
Kilo Patron
Kilo Patron

Hi @nameisnani ,

 

You have to utilize notification email scripts to pull out the variables of the catalog item.

Create new record in notification email script as below:

SN_Learn_0-1718857107122.png

 

Then call the above script in notification as below:

SN_Learn_1-1718857167572.png

 

${mail_script:scriptName}

 

Mark this as Helpful / Accept the Solution if this clears your issue

 

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Ankur Bawiskar
Tera Patron
Tera Patron

@nameisnani 

try this and replace your correct variable name

${current.variables.requested_for}

If the above doesn't work then

you can store those variables in workflow scratchpad and then use in notification like this

1) run script

workflow.scratchpad.requestedFor = current.variables.requested_for;
workflow.scratchpad.deviceStolenDate = current.variables.<dateVariable>;

2) in notification message use like this

A lost or stolen device has been reported by ${workflow.scratchpad.requestedFor}
The device was lost or stolen on ${workflow.scratchpad.deviceStolenDate}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

nameisnani
Mega Sage

@Ankur Bawiskar @SN_Learn 

 

still error is coming 

nameisnani_5-1718862050282.png

 

 

This is my mail script 

nameisnani_1-1718861741422.png

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

    var requester = current.requested_for.getDisplayValue();
    var date = current.variables.date_item_was_lost_stolen.getDisplayValue();

    email.setSubject(current.short_description_1);
    template.print("<p>A lost or stolen device has been reported by " + requester);
    template.print("<p>The device was lost or stolen on " + date);
    template.print("<br />");
    template.print("Description:" + current.description_1);



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

 

 

This is the catalog

nameisnani_2-1718861844641.png

 

 

 

Short description and description we are getting from variable set 

 

nameisnani_3-1718861893700.png

 

 

You can see in the notification preview short descp and descirption are shwoing undefined ,  

nameisnani_4-1718862031525.png

 

 

@Ankur Bawiskar @SN_Learn 

 

can you please tell me what was the mistake here and what correction required .

@nameisnani 

you are using the wrong syntax to get variable value

the correct syntax is current.variables.variableName

update as this

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

    var requester = current.variables.requested_for.getDisplayValue();
    var date = current.variables.date_item_was_lost_stolen.getDisplayValue();

    email.setSubject(current.variables.short_description_1);
    template.print("<p>A lost or stolen device has been reported by " + requester);
    template.print("<p>The device was lost or stolen on " + date);
    template.print("<br />");
    template.print("Description:" + current.variables.description_1);



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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader