How to call the multiple events in the one Notification

is_12
Tera Contributor

Hello Community !

 

I need create one new notification when the needs attentions is true on the sc_task

For this

Trigger condition: 1. state changes from Pending to Work in progress

2.Additional comments updated by customer/ not assigned to

3.Catalog type is SSR

 

Should I need to create a multiple events for each one of  this three conditions, if so then how to implement that.

If not how to achieve this.

 

 

Looking forward for the working solution

Thank you 

2 ACCEPTED SOLUTIONS

@is_12 

Don't use Event, let notification get trigger based on updated checkbox on sc_task table

for checking this -> 2.Additional comments updated by customer/ not assigned to

You can use advanced notification condition and script

Something like this and enhance it further

AnkurBawiskar_0-1746778176695.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

@is_12 

then use toString() to compare and also use gs.getUserName() to get user ID at line 10

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

    gs.info('userID7');

    var comments = '';
    var userId = gs.getUserName(); // Get the logged-in user ID
    gs.info('userID9' + userId);
    var requestorId = current.request_item.requested_for.user_name.toString();

    gs.info('userID14' + requestorId);

    var gr = new GlideRecord('sys_journal_field');
    gr.addQuery('element_id', current.sys_id);
    gr.addQuery('element', 'comments');
    gr.orderByDesc('sys_created_by');
    gr.query();

    gs.info('userID14' + requestorId);
    gs.info('created by' + gr.sys_created_by);
    if (gr.next()) {
        gs.info('userID25', +comments);
        if (gr.sys_created_by.toString() == userId || gr.sys_created_by.toString() == requestorId) {

            gs.info('userID23' + comments);
            comments += gr.value + '\n';
        }
    }

    gs.info("userID32" + comments);
    template.print('The task ' + current.number + ' has been updated by the customer with below comments ' + comments + '\n');


})(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

15 REPLIES 15

Hello @Ankur Bawiskar 

Thanks for the solution, Mail is getting triggered

And in the body : The task (task number) has been updated by the customer with below comments [Append the comments added by customer] Display View Ticket and redirect it to our Support portal.

This should be content in the body. for the appending the comments, I have written a script , you can find it below :

    gs.info('userID7');


    var comments = '';
    var userId = gs.getUserID(); // Get the logged-in user ID
    gs.info('userID9'+userId);
    var requestorId = current.request_item.requested_for;


    var gr = new GlideRecord('sys_journal_field');
    gr.addQuery('element_id', current.sys_id);
    gr.addQuery('element', 'comments');
    gr.orderByDesc('sys_created_on');
    gr.query();

    while (gr.next()) {
        if (gr.sys_created_by == userId || gr.sys_created_by == requestorId) {
            gs.info('userID23'+comments);
            comments += gr.value + '\n';
        }
    }


    template.print('The task '+current.number +' has been updated by the customer with below comments ' + comments + '\n');
   basically only if the customer or the primary contact updates the additional comments, that should be printed in the body
if the assigned to adds the comments or the system user adds the comments that should be coming the body
But script in not working 
in the logs only still here I'm getting 

Thanks for the solution, Mail is getting triggered

And in the body : The task (task number) has been updated by the customer with below comments [Append the comments added by customer] Display View Ticket and redirect it to our Support portal.

This should be content in the body. for the appending the comments, I have written a script , you can find it below :

    gs.info('userID7');


    var comments = '';
    var userId = gs.getUserID(); // Get the logged-in user ID
    gs.info('userID9'+userId);
can you help me with this 
 
Thanks
 

@is_12 

did you debug by adding gs.info() statements?

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

yeah @Ankur Bawiskar , it is working till the 2nd info.

Should I need to make any changes to script.

@is_12 

you need to dot walk requested_for to know the userID

gs.info('userID7');


var comments = '';
var userId = gs.getUserID(); // Get the logged-in user ID
gs.info('userID9'+userId);
var requestorId = current.request_item.requested_for.user_name;


var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', current.sys_id);
gr.addQuery('element', 'comments');
gr.orderByDesc('sys_created_on');
gr.query();

if(gr.next()) { // use IF
if (gr.sys_created_by == userId || gr.sys_created_by == requestorId) {
gs.info('userID23'+comments);
comments += gr.value + '\n';
}
}template.print('The task '+current.number +' has been updated by the customer with below comments ' + comments + '\n');

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

Hello @Ankur Bawiskar 

I made the changes you told and tried but still it is the same 

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

    gs.info('userID7');

    var comments = '';
    var userId = gs.getUserID(); // Get the logged-in user ID
    gs.info('userID9' + userId);
    var requestorId = current.request_item.requested_for.user_name;

    gs.info('userID14' + requestorId);

    var gr = new GlideRecord('sys_journal_field');
    gr.addQuery('element_id', current.sys_id);
    gr.addQuery('element', 'comments');
    gr.orderByDesc('sys_created_by');
    gr.query();

    gs.info('userID14' + requestorId);

    if (gr.next()) {
        gs.info('userID25', +comments);
        if (gr.sys_created_by == userId || gr.sys_created_by == requestorId) {
           
            gs.info('userID23' + comments);
            comments += gr.value + '\n';
        }
    }

    gs.info("userID32" + comments);
    template.print('The task ' + current.number + ' has been updated by the customer with below comments ' + comments + '\n');


})(current, template, email, email_action, event);
 
is_12_0-1747043234194.png

in logs as well UserID23 is not coming up

 

Thanks,