Hi Community we need help on the notification to trigger for the additional not to work notes

rajeshKongamudi
Tera Contributor

Dear Community,

We have developed a script to handle notifications for SC tasks and RITM users. The script is designed to send notifications only when the SC task user and the RITM user are the same. However, there are existing notifications in place, which may also trigger additional notifications, leading to duplicates. As a result, our client has requested that duplicate notifications be avoided, ensuring that only one notification is sent under these circumstances.

The current functionality works as follows: if the SC task user and the current user are the same, the notification is not sent. This condition has been successfully implemented. However, the client has additional requirements regarding the handling of "Additional Comments" versus "Work Notes." Specifically:

  1. If the "Additional Comments" field changes and the user is the same for both the SC task and RITM, the notification should not be sent.
  2. If the "Work Notes" field changes and the user is tagged (for example, @Edith), the notification should be sent, even if the request user is the same as the SC task user.

To summarize, we need to configure the system such that notifications are restricted only when the "Additional Comments" field is modified and the users are the same. If the "Work Notes" are updated, notifications should still be sent, even if the request user is the same.

Could you please assist us with the configuration to meet these requirements?

Thank you.

sc_task

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

    else if (current.table == 'sc_task') {
        var gr = new GlideRecord('sc_task');
        gr.addQuery('number', current.title);
        gr.addQuery('request.requested_for', current.user);
        gr.query();
        //gs.log('before if condition');
        if (gr.next()) {
            //gs.log('requested for'+ gr.request.requested_for);
            //gs.log('number'+ gr.number);
            //gs.log('Live notification user'+ current.user);
                   if (gr.isFieldModified(gr.comments)) {
            // If 'additional_comments' was modified, return false to stop further actions
            return false;
        }
        }

    }
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@rajeshKongamudi 

can you try this? Also use business rule to check the field is modified or not and don't directly use notification as you don't have access to previous object in notification advanced condition script

1) Check if the "Additional Comments" field is modified and the users are the same: If true, do not send the notification.
2) Check if the "Work Notes" field is modified and the user is tagged: If true, send the notification.

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

Hi @Ankur Bawiskar , Thank you for your response. However, we would like to incorporate this condition directly into the script, as we have already written additional conditions for other tables. Could you please guide us on how to add a condition that returns true only if the 'Additional Comments' field has changed, and ensures that the notification is not triggered if only the 'Work Notes' field has changed?

 

Here is the entire script: we need for only sc_task and RITM table to applicable for.

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

function shouldSend() {



    if (current.table == 'incident') {
        var grinc = new GlideRecord('incident');
        grinc.get(current.document);

 

        // If portfolio is not 'caf' and caller_id is not the same as the current user, send notification
        if (grinc.u_portfolio.getValue() != gs.getProperty('portfolio.caf') && grinc.caller_id != current.user) {
            gs.log("Notification Activity Stream Working fine. Either portfolio is not 'caf' or caller_id is not current user.");
            return true// Send notificationnnn
        }
       
        else if ((grinc.u_portfolio.getValue() != gs.getProperty('portfolio.caf') && grinc.caller_id == current.user) || grinc.u_portfolio.getValue() == gs.getProperty('portfolio.caf'))
       
        {
            gs.log("Notification Activity Stream blocked. Either portfolio is not 'caf' or caller_id is current user || Either portfolio is 'caf'");
            return false// Notification should not be sent
        }
    }

 

    //If the requested_for user & mentioned user is same then notification should not be sent for sc task table
    else if (current.table == 'sc_task') {
        var gr = new GlideRecord('sc_task');
        gr.addQuery('number', current.title);
        gr.addQuery('request.requested_for', current.user);
        gr.query();
        //gs.log('before if condition');
        if (gr.next()) {
            //gs.log('requested for'+ gr.request.requested_for);
            //gs.log('number'+ gr.number);
            //gs.log('Live notification user'+ current.user);
                   if (gr.isFieldModified(gr.comments)) {
            // If 'additional_comments' was modified, return false to stop further actions
            return false;
        }
        }

 

    }

 

    //If the requested_for user & mentioned user is same then notification should not be sent for requested_item table
    else if (current.table == 'sc_req_item') {
        var grreq = new GlideRecord('sc_req_item');
        grreq.addQuery('number', current.title);
        grreq.addQuery('requested_for', current.user);
        grreq.query();
        //gs.log('before if condition');
        if (grreq.next()) {
            //gs.log('requested for'+ gr.requested_for);
            //gs.log('number'+ gr.number);
            //gs.log('Live notification user'+ current.user);

 

            return false;
        }

 

    }
        var liveGroupProfileGR = new GlideRecord("live_group_profile");
    liveGroupProfileGR.setWorkflow(false);
    liveGroupProfileGR.addQuery("document", current.document);
    liveGroupProfileGR.addQuery("table", current.table);
    liveGroupProfileGR.addQuery("type""!=""support");
    liveGroupProfileGR.query();

 

    if (liveGroupProfileGR.next()) {
        var liveGroupMemberGR = new GlideRecord("live_group_member");
        liveGroupMemberGR.setWorkflow(false);
        liveGroupMemberGR.addQuery("group", liveGroupProfileGR.getUniqueValue());
        liveGroupMemberGR.addQuery("member", current.profile);
        liveGroupMemberGR.addQuery("state""!=""inactive");
        liveGroupMemberGR.query();

 

        if (liveGroupMemberGR.next()) {
            return false;
        }
    }

 

    var SecurityManager = new SNC.LiveFeedSecurityManager();
    return SecurityManager.canReadField(current.user, current.table, current.document, current.field_name);
}

 

shouldSend();

@rajeshKongamudi 

that's what I said, you cannot determine in notification advanced script if field got changed and hence you need to move that logic to business rule where you have access to current and previous object

the script you shared is in advanced notification condition field? notification is on which table?

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