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

nataliya_b
Tera Guru

in your condition you are passing current.sys_id, but in script include, function takes object current, not sys id

 

so, you need to update your script as below

 

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

checktaskclosure :function(sysid) {

var grt = new GlideRecord('sn_hr_core_task');
grt.addQuery('parent', sysid);
grt.addQuery('short_description', 'Step1 Task');
grt.query();

 

 

please let me know if it works

Hi @nataliya_b ,

The UI action visibility is still not working , it is visible everytime when form loads. Please guide.

However the script started working atleast and it is entering into loop after making changes.

The condition in the UI Action is below 

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

I have updated the Script include as you mentioned . 

var SteptaskUtils = Class.create();
SteptaskUtils.prototype = {
    initialize: function checktaskclosure(sysid) {
		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'

};

I have checked the log statements , I observed that it is generating the log statement for each Twice .Please see the below showing twice.

find_real_file.png

find_real_file.png

find_real_file.png

could you place here the latest version of your script include?

also, in condition could you place code as below

 

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

Hi ,

Please find the below Script include 

var SteptaskUtils = Class.create();
SteptaskUtils.prototype = {
    initialize: function checktaskclosure(sysid) {
		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'

};

I have updated the Condition in the UI action as below .

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

 

Request to guide me where exactly I am missing for this work .

please replace your script with the code below

and let me know if it works

 

var SteptaskUtils = Class.create();
SteptaskUtils.prototype = {


iinitialize: function() {},

checktaskclosure: function (sysid) {
gs.info('Into the Script Include:');
var grt = new GlideRecord('sn_hr_core_task');
grt.addQuery('parent', sysid);
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'