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

Jaspal Singh
Mega Patron
Mega Patron

Seems, worklog is a custom table. If so, can you replace

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

with

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

Hi Jaspal, 

 

I tried to change to parent but still not working, actually worklog is a custom table, extends from task table. 
please suggest if any things needs to be looked at

manjusha_
Kilo Sage

@E698858 

 

u_work_log field refers to the change record ,if yes your code is ok ,just use if instead of while.

use gs.info() method to check short description values

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

Thanks,

Manjusha Bangale

Hi Manjusha, 

Thankyou for suggesting, but no its not working still. can you please help with the code, as worklog being a custom table extending task table. 
Short Description filed value is not retrieved in email