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

@is_12 

did you check who is the gr.sys_created_by

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 

yeah, it is the same user 

is_12_0-1747044085583.png

 

@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

Hello @Ankur Bawiskar 

It is working now I have made few changes

    var addComments;
    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()) {
        addComments = gr.value.toString();
        gs.info('userID23 :: ' + addComments);
        var arrWorknotes = addComments.split(':');
        var storedValue = arrWorknotes[1];

    }

    template.print('The task ' + current.number + ' has been updated by the customer with below comments \n"' +storedValue +  '"\n');
 
is_12_1-1747057400768.png

Thanks for your response 

@is_12 

Glad to help.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader