Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Call script include in UI action for specific field users

Ash41
Kilo Sage

Hi Team, 

 

I want to create Script include for below condition to call in UI action, in UI action I can't mention it has reached maximum character

 

current.requested_by == gs.getUserID() || current.requested_by.manager== gs.getUserID() 

 

Please suggest, thank you

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

You can replace the above with only your SI call, passing in current.requested_by as an argument.  In the SI, do whatever you were going to do, then also check if the current user is the requested_by or their manager and return the appropriate true or false for all of those conditions.

Sandeep Rajput
Tera Patron
Tera Patron

@Ash41 Here is how you can create a script include to capture this condition.

var CheckConditionSI = Class.create();
CheckConditionSI.prototype = {
    initialize: function() {
    },

    checkCondition: function(current) {
        // Get the requested_by and their manager from the current object
        var requestedBy = current.requested_by;
        var userID = gs.getUserID();

        // Check if the current user is the requested_by or their manager
        return requestedBy == userID || requestedBy.manager == userID;
    },

    type: 'CheckConditionSI'
};

 

Here is how you should call this script include from the condition field of your UI Action.

new CheckConditionSI().checkCondition(current);

Hope this helps.