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

Harsh Vardhan
Giga Patron

UI Action and SCript include are in same scope ?

if not then make your script include "Accessible from" to all scope.

Harsh Vardhan
Giga Patron

ahh got it. the issue is you are missing 

 

next()

 

it should be if(grt.next()) before the var gh

Harsh Vardhan
Giga Patron

glide record example:

 

var rec = new GlideRecord('incident');
rec.query();
if(rec.next()) { // this part you were missing in your script include 

gs.print(rec.number + ' exists');

}

Harsh Vardhan
Giga Patron

updated script:

 

 

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());
if(grt.next()){

var gh = grt.state;
        if (gh == '3') {

            return true;
        }
		else{
			
			return false;
		}
}


    },


    type: 'SteptaskUtils'

};