Can you use previous on a notification?

matthew_hughes
Kilo Sage

On a notification, I only want it to trigger if the following conditions are met:

if (previous.getValue('u_cmdb_data_steward.manager') == current.getValue('u_cmdb_data_steward')) {
    answer = true;
}
 
The above query checks if the previous manager of the steward is the current steward. Can you use previous in a notification?
22 REPLIES 22

Thanks @Ankur Bawiskar .

 

That works. However, there is the case that a user can be assigned to more than one role, so we need to avoid duplicate emails being sent. I tried the writing the following code, but it didn't work:

 

(function executeRule(current, previous /*null when async*/ ) {
    gs.log("MH - The previous DAO is " + previous.u_business_owner.getDisplayValue());
    gs.log("MH - The current DAO is " + current.u_business_owner.getDisplayValue());
    newOwnersLoop = [];
    var newBusinessApplicationSteward = current.u_cmdb_data_steward;
    var newTechnicalApplicationOwner = current.u_custodian;
    var newBusinessApplicationOwner = current.u_business_owner;
    if (previous.getDisplayValue('u_cmdb_data_steward.manager') == current.getDisplayValue('u_cmdb_data_steward')) {
        if (newOwnersLoop.indexOf(newBusinessApplicationSteward) == -1) {
            newOwnersLoop.push(newBusinessApplicationSteward);
            gs.log('MH - This should display lbg.notify.reassignBAS');
            gs.eventQueue('lbg.notify.reassignBAS', current, newBusinessApplicationSteward, previous.u_cmdb_data_steward.getDisplayValue());
        }
    }


    if (previous.getDisplayValue('u_custodian.manager') == current.getDisplayValue('u_custodian')) {
        if (newOwnersLoop.indexOf(newTechnicalApplicationOwner) == -1) {
            newOwnersLoop.push(newTechnicalApplicationOwner);
            gs.log('MH - This should display lbg.notify.reassignTAO');
            gs.eventQueue('lbg.notify.reassignTAO', current, newTechnicalApplicationOwner, previous.u_custodian.getDisplayValue());
        }
    }


    if (previous.getDisplayValue('u_business_owner.manager') == current.getDisplayValue('u_business_owner')) {
        if (newOwnersLoop.indexOf(newBusinessApplicationOwner) == -1) {
            newOwnersLoop.push(newBusinessApplicationOwner);
            gs.log('MH - This should display lbg.notify.reassignDAO');
            gs.eventQueue('lbg.notify.reassignDAO', current, newBusinessApplicationOwner, previous.u_business_owner.getDisplayValue());
        }
    }
    // Add your code here

})(current, previous);
 
What else can I do to prevent duplicate emails being sent?

@matthew_hughes 

I believe I have answered your original question.

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

You are trying to perform previous on a dotwalked field? That will never work unfortunately. I missed that in your question, my bad. Though such logic will never work.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn