Regarding creation of notification when catalog task is not being closed after 1 week

Shreya3
Tera Contributor

how we can built from scratch the code for creating notification to be sent to technology Ci Owner manager and cc technology ci owner and suppport group if catalog task has not yet been closed after 1 week. And also need help for creating notification to be sent to technology Ci Owner manager and cc technology ci owner and suppport group to create p1 incident and then send email if catalog task has not yet been closed after 2 weeks . please help on this. I have created  2 event registry  , 2 email notification and 1schedule job. but in schedule job i am not able to put proper code for both of the scenarios can anybody help on this asap, as I am new to this.

26 REPLIES 26

Hi @Shreya3, 

Hope you are doing well.

 

As a solution, you need to create a new "Notification Email Script" that will execute the logic or implementation of adding a CC people. You need to add this line mentioned below in "Notification Email Script": -

 

email.addAddress('cc', 'aakash.garg@example.com', 'Aakash Garg');

 

After creating and adding the above line in "Notification Email Script" successfullyYou need to add this line mentioned below in the Notification record's Body as: -

 

Do not forget to replace <email-script_name> with the name of Notification Email Script record's name.

${mail_script:<email_script_name>} // Replace <email_script_name> with the Notification Email Script Name Created

 

Hope this solution will resolve your concern or issue and please don't forget to mark my solution as helpful and accepted.

 

Thanks 🙂

Aakash Garg

ServiceNow Developer

Akash sc_task table has configuration item field and when we open record of configuration item there we have Technology ci owner field and support group field which is a reference field. so any person can be added in these 2 fields. So how can we write email notification script for this CC people? In the above you have shown like for particular user but here case is different. Can you help?

Hi @Shreya3, 

Hope you are doing well.

 

For this scenario, you need to fetch and extract the data from an arrays (tasks_7days and tasks_7days) into the "Notification Email Script" as you can see that we are already passing these arrays into "eventQueue" in Schedule Job and then you need to do the dot walking to get the users from the fields present in "Configuration Item" Field to add it into CC.

 

Let me know if you need script for this, and if any of the reply or solution giving or helping you in getting any kind of information, please don't forget to mark my solutions and replies as helpful and accepted. 

 

Thanks 🙂

Aakash Garg

ServiceNow Developer

akash can you provide me script for this.? 

Hi @Shreya3,

Glad to see that you are following my solutions being posted to get your queries resolved as soon as possible.

 

As a solution and on your demand, attaching the script for your reference and I personally created and implemented it on my Personal Developer Instance. Hope this will fulfil your requirement.

 

Notification Email Script: -

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

    // Add your code here
    var val = event.parm1.split(',');
    template.print('<table border="2"><caption style="font-size:150%; font-weight:bold; font-family: Times New Roman, Times, serif; background: linear-gradient(to right, #F8D90F, #FE7A15); -webkit-text-fill-color: transparent;-webkit-background-clip: text;">License Details</caption>');
    template.print('<tr style="background: linear-gradient(to right, #A9F1DF, #FFBBBB);"><th>Number</th><th>Item</th><th>Priority</th><th>Short Description</th><th>Assignment Group</th><th>Assigned To</th><th>Configuration Item</th></tr>');
    for (var i = 0; i < val.length; i++) {
        var gr = new GlideRecord('sc_task');
        gr.addQuery('sys_id', val[i]);
        gr.query();
        if (gr.next()) {
			email.addAddress('cc', gr.cmdb_ci.owned_by.email, gr.cmdb_ci.owned_by.getDisplayValue());
            template.print('<tr style="background: linear-gradient(to right, #D8B5FF, #1EAE98);"><td style="width:35%;">' + gr.number + '</td><td>' + gr.request_item.cat_item.getDisplayValue() + '</td><td style="width:10%;">' + gr.getDisplayValue('priority') + '</td><td>' + gr.short_description + '</td><td>' + gr.getDisplayValue('assignment_group') + '</td><td>' + gr.getDisplayValue('assigned_to') + '</td><td style="width:15%;">' + gr.getDisplayValue('cmdb_ci') + '</td></tr>');
        }
    }
    template.print('</table>');

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

 

After creating and adding the "Notification Email Script" successfully, you need to add this line mentioned below in the Notification record's Body as: -

${mail_script:email_notify_template}

 

Your appreciation and feedback mean a lot to me. So, please don't forget to mark my solutions and replies as helpful and accepted.

 

Thanks 🙂

Aakash Garg

ServiceNow Developer