Email Script Not working

JVINAY
Tera Contributor

Hello,

 I have written below Email script 

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

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

    // Add your code here
    if(current.getTableName() == 'u_cloud_intake_task') {
        var url1 = gs.getProperty('glide.servlet.uri') + 'u_cloud_intake_request?sys_id=' + current.getValue('sys_id');
        template.print('<a href="' + url1 + '">' + current.getValue('number') + '</a>');
    } else if(current.getTableName() == 'u_cloud_intake_request') {
        var url2 = gs.getProperty('glide.servlet.uri') + 'u_cloud_intake_request?sys_id=' + current.getValue('sys_id');
        template.print('<a href="' + url2 + '">' + current.getValue('number') + '</a>');
    }
--------------------------
 
I have added this email script in One notification body , 
Out put :

it getting CIT number , I want CIR number,

Please help me .

Thank you

2 ACCEPTED SOLUTIONS

@JVINAY 

earlier you said the notification is on u_cloud_intake_request  table so I gave script accordingly

AnkurBawiskar_0-1754481565153.png

 

If notification is on u_cloud_intake_task and you want to show REQ then simply use this and no email script required

Use the correct field name on the u_cloud_intake_task which refers to the Intake Request

AnkurBawiskar_1-1754481898414.png

 

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

@JVINAY 

is the field name "u_cloud_intake" on intake task referring to intake request?

share field configuration screenshot

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

22 REPLIES 22

@JVINAY 

you added wrong code code log.

add this at the beginning i.e. just above the IF

gs.info('table is' + current.getTableName());

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

@Ankur Bawiskar 

I have updated this code

JVINAY_0-1754476233990.png

Output :

JVINAY_1-1754476269656.png

CIR number is empty , Please suggest modifications

 

Thank you.

@JVINAY 

you can directly include link to record without email script in email body itself

check this

1) use the insert link option

AnkurBawiskar_0-1754476784425.png

 

2) then add details like this in that link

AnkurBawiskar_1-1754476805985.png

 

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

@Ankur Bawiskar 

 

Is it working statically or dynamically? We have three environments: DEV, TEST, and PROD. Suppose a notification is triggered in the TEST environment—it should redirect to the corresponding record on the Test Platform. Similarly, for DEV and PROD, it should redirect to their respective platform records

 

Thank you for your responce

@JVINAY 

it will work in all environments as the URL is relative and not static and will pick the instance name etc automatically.

You can hover over that link and see it adds DEV instance automatically.

If you see I haven't included any instance name etc so it will work in all DEV, TEST and PROD.

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