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.

UI Action visibility Restriction based on Script include result

Mrman
Tera Guru

Hi All,

I have created a UI action in Scoped Application to show on the Case form when the 1st Task created is moved to Closed state . 

This UI action should only be visible when Step 1 task is closed .  I am making a call to Script Include to query the table and return 'true' Or 'false' .

The Condition used to restrict the visibility of UI action is not working . Could you let me know if I am missing something in my Script .

Below is the UI Action 

find_real_file.png

 

Below is the Script Include :

find_real_file.png

var SteptaskUtils = Class.create();
SteptaskUtils.prototype = {
    initialize: function checktaskclosure(current) {
        var grt = new GlideRecord('sn_hr_core_task');
        grt.addQuery('parent', current.sys_id);
        grt.addQuery('short_description', 'Step1 Task');
        grt.query();
		gs.info('the returned records are :' + grt.getRowCount());
		var gh = grt.state;
        if (gh == '3') {

            return true;
        }
		else{
			
			return false;
		}


    },


    type: 'SteptaskUtils'

};
1 ACCEPTED SOLUTION

hi, could you please test this one

in condition, we will pass object current

new sn_hr_core.SteptaskUtils().checktaskclosure(current);

 

script include as below

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

checktaskclosure: function(current) {
gs.info('Into the Script Include:');
var grt = new GlideRecord('sn_hr_core_task');
grt.addQuery('parent', current.sys_id);
grt.addQuery('short_description', 'Step1 Task');
grt.query();
gs.info('the returned records are :' + grt.getRowCount());
if(grt.next()){

var gh = grt.state;
gs.info('the state value is :' + gh);
if (gh == '3') {

return true;
}
else{
gs.info('Into Else:');
return false;
}

}
},


type: 'SteptaskUtils'

};

View solution in original post

22 REPLIES 22

Hi ,

This logic is working only for one UI action , if I add Step3 UI action to check closure of Step2 task it is not working , I can see both Step2 and Step3 UI actions visible even after Step2 task is moved to Closed state .

Do I need to use any Loop to take the count of Tasks getting created and check their Closure ?

Please Guide

try these 4

ui action #1:

condition: new sn_hr_core.SteptaskUtils().checktaskclosure(current, 'Step1 Task');

 

ui action #2: new sn_hr_core.SteptaskUtils().checktaskclosure(current, 'Step2 Task');

 

have you script include changed to below

(assumtion, that state is the same(=3) for both checked tasks)

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

checktaskclosure: function(current,strTask) {
gs.info('Into the Script Include:');
var grt = new GlideRecord('sn_hr_core_task');
grt.addQuery('parent', current.sys_id);
grt.addQuery('short_description', strTask);
grt.query();
gs.info('the returned records are :' + grt.getRowCount());
if(grt.next()){

var gh = grt.state;
gs.info('the state value is :' + gh);
if (gh == '3') {

return true;
}
else{
gs.info('Into Else:');
return false;
}

}
},


type: 'SteptaskUtils'

};

Hi @nataliya_b ,

Could you please let me know how do I add Role in the condition of UI action .

The current condition which I gave is not restricting the users and a user with itil is able to see these UI action when they open the case.

I gave the condition as below but it is not working , please suggest

current.state == 40 && (!current.isNewRecord() || current.canCreate())&&(gs.getUser().hasRole('sn_hr_core_case_writer'));