Email Script to display a variable value in notification of change

E698858
Tera Contributor

The change request has a related list table Worklog, which will capture the cancel reason for the change in "Short Description" 
The  value of short description should be displayed in the email notification for change. 

I have tried using a Notification Email script and calling the script in email body. 

But my script is not working as expected. 

 

Can someone please let me know how to fix this.. 

 

 

Notification Email Scripts 

-------------

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,

    /* Optional EmailOutbound */

    email, /* Optional GlideRecord */ email_action,

    /* Optional GlideRecord */

    event) {

            var gr = GlideRecord('u_work_log');

            gr.addQuery('u_work_log', current.sys_id);

            gr.query();

            while(gr.next())

                        {

            gs.getDisplayValueFor(current.getTableName(), current.getValue('string'),'short_description');                    

                        }

    //template.print(gr.u_entry_log);

            //template.print(gr.getDisplayValue('u_entry_log'));

            template.print(gr.short_description);

            //template.print(gr.getDisplayValue('short_description'));

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

1 ACCEPTED SOLUTION

@E698858 

 

You won't get the short description of work log record using u_work_log field.

You need a reference field which refers to the parent ticket which your change record 

There is a field-'parent' on work log table as per your screenshot.

So we can use it to get the short descript-Please update your code as below

 

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

var work_log_description ='';
var gr = GlideRecord('u_work_log');
gr.addQuery('parent', current.sys_id);//this parent is the name of Parent field on worklog table-as per your screenshot ,please check Parent field's name and update it  if it is not correct 
gr.query();
if(gr.next())
{

work_log_description = gr.getValue('short_description');//please check whether short description name is correct or not on worklog table
}
//template.print(gr.u_entry_log);
//template.print(gr.getDisplayValue('u_entry_log'));
template.print(work_log_description);
//template.print(gr.getDisplayValue('short_description'));
})(current, template, email, email_action, event);

 

Syntax to call this email script in your notification as below-

${mail_script: email_script_name}

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

 

 

 

 

 

View solution in original post

8 REPLIES 8

@E698858 

could you please share type details of field-u_work_log

also share your updated script.

 

Thanks,

Manjusha Bangale

Hi @manjusha_ 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var gr = GlideRecord('u_work_log');
gr.addQuery('u_work_log', current.sys_id);
gr.query();
if(gr.next())
{
gs.getDisplayValueFor(current.getTableName(), current.getValue(short_description));
gs.log('trigger notification, ctask: ' + gr.short_description.getDisplayValue());
var wlog = current.getValue('short_description');
}
//template.print(gr.u_entry_log);
//template.print(gr.getDisplayValue('u_entry_log'));
template.print(gr.short_description);
template.print(gr.getDisplayValue('short_description'));
})(current, template, email, email_action, event);

 

Please find the attached image for work log table field types (Worklog1.PNG)

@E698858 

 

You won't get the short description of work log record using u_work_log field.

You need a reference field which refers to the parent ticket which your change record 

There is a field-'parent' on work log table as per your screenshot.

So we can use it to get the short descript-Please update your code as below

 

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

var work_log_description ='';
var gr = GlideRecord('u_work_log');
gr.addQuery('parent', current.sys_id);//this parent is the name of Parent field on worklog table-as per your screenshot ,please check Parent field's name and update it  if it is not correct 
gr.query();
if(gr.next())
{

work_log_description = gr.getValue('short_description');//please check whether short description name is correct or not on worklog table
}
//template.print(gr.u_entry_log);
//template.print(gr.getDisplayValue('u_entry_log'));
template.print(work_log_description);
//template.print(gr.getDisplayValue('short_description'));
})(current, template, email, email_action, event);

 

Syntax to call this email script in your notification as below-

${mail_script: email_script_name}

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

 

 

 

 

 

Thank you @manjusha_  : It worked !!