Flow Designer Question with Subflows

RacheleTashjian
Tera Contributor

I have a subflow in most of my workflows that will assign a user license entitlement to the software model as part of the workflows.  

 

I need the subflow (which is create software model entitlement) to check the existing entitlements and prevent duplicates from being created.  

 

I have a script that works as a business rule, but stops my flow from completing because it throws an error in the flow and stops it entirely.

 

I'm trying to incorporate the script into the subflow to create the entitlement, but I can't get it to work properly.  Any suggestions, thoughts or ideas on how to accomplish this?

 

 

3 REPLIES 3

Peter Bodelier
Giga Sage

Hi @RacheleTashjian 

It would help if you could add the script you are trying to add. 🙂


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

I set up a business rule with a script which works to prevent duplicate entitlements, but it stops the flow at the error creating the entitlement if it finds a duplicate.

Here's what i have, let me know if you have any questions (i created u_duplicate_found on the entitlement table to track/hold)

 

(function executeRule(current, previous /*null when async*/) {
    // Get the user ID from the current record
    var userID = current.user_id;

    // Query the alm_entitlement_user table to check for existing entitlements
    var entitlementGR = new GlideRecord('alm_entitlement_user');
    entitlementGR.addQuery('user_id', userID);
    entitlementGR.addQuery('entitlement', current.entitlement);
    entitlementGR.query();

    // If an existing entitlement is found, set a flag
    if (entitlementGR.next()) {
        current.u_duplicate_found = true;
    } else {
        current.u_duplicate_found = false;
    }
})(current, previous);

 

Ankur Bawiskar
Tera Patron
Tera Patron

@RacheleTashjian 

you can use Lookup Record action in your flow and check if entitlement already present for that user.

Then use IF logic and if no entitlement present for user then create

Don't use business rule in that case to avoid duplicates.

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