Goran WitchDoc
ServiceNow Employee

I got this question about how to be able to put more advanced condition on a UI Action.

In this case specific we want to have a UI Action that will only show on incidents if there isn't any active childs incidents connected to it.

It will be pretty straight forward and use it as a simple example on how to use this for more complex situations you will get yourself into 😃

first we need to create the Script Include. If you don't know exactly how your code to to validate if your function should return true of false, play around with it in Script - background or fix script. By that way you can easy and fast test the code to make sure it will return the right values.

I have chosen to call my Script Include for condUtil, so it will say something about what it is and I can add more functions in it later that are connected to conditions.

Don't forget to at least write a few lines about what you expect the function to get as input and what it is suppose to return

Here is what the Script Include looks like:

find_real_file.png

As you can see here I created a function called "checkIncidentChilds" which takes in one parameter and this uses this to see if that sys_id has any active childs connected.

And returns true or false depending on there is any active childs.

Now I can use this on the condition field on an UI Action like this:

find_real_file.png

since it will return true if the incident doesn't have any active childs, the button will then be visible, otherwise it will return false and the button will not be seen.

By doing this you can easy create reusable conditions which can do complex checks and just return true or false.

I hope this will get your imagine going and make some magic happen.

8 Comments
rhett1
Tera Expert

Ok I thought this was going to be straight forward, but when I add:



countChilds.addQuery('u_status', 8);



It comes back as undefined.   The requirement:   The UI Action should not appear until the status is OPEN (which is u_status = 8).



I looking to poll the u_status found in the grc_observation table from the grc_remediation table.



I am on Helsinki.   Would this example support this requirement?


Goran WitchDoc
ServiceNow Employee

Hi rhett,



The countChilds a a gliderecord from the incident table. As I understand your u_status isn't from that table, is that correct?



//Göran


rhett1
Tera Expert

Thank you Göran for the response.   You are correct the u_status is not from that table.   It is coming from the grc_observation table.   I did finally figure it out and here is a link to how I accomplished it:



UI Action Condition and Script Include Produces Undefined


Goran WitchDoc
ServiceNow Employee

Great 😃


Brett Ishmael
Tera Contributor

Very helpful, thank you

aravind23
Tera Contributor

 

 

Erik Stuer
Tera Guru

Hi Goran,

I am struggling to use a script include to control my UI Action's condition field. I am using this script include:

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

getCondition: function(current) { 
var userID = gs.getUserID();
var hasManagerRole = gs.hasRole('sn_risk.manager');
var isOwnerAndItrac = gs.hasRole('u_risk_user_special') && current.owner.getUniqueValue() === userID; 
var isCorrectState = (current.state === 'review') || (current.state === 'respond' && current.attestation.nil());
var canRead = current.canRead();
return (hasManagerRole || isOwnerAndItrac) && isCorrectState && canRead;
},

type: 'riskRetireUiActionCondition'
};
And I am using this in my condition field:
new riskRetireUiActionCondition().getCondition(current)
But when impersonating a user that has the role - u_risk_user_special but not the sn_risk.manager role and is NOT listed as the owner, this user can still see the UI Action. I don't see what I am doing wrong. Any help would be greatly appreciated!

hamzai
Tera Explorer

Thank you so much !!