How to hide button from form on condition?

IamAmolB
Tera Guru

Hi Experts,

I have written this code but it is not able to run can you please suggest what to do any update on below code. please suggest

find_real_file.png

No error No warnings.

still not able to run. please suggest.

1 ACCEPTED SOLUTION

Hi Amol,



Search for the ui action that you want to hide.


Open it, you will find condition field in it. You can mention your condition for the visibility of that ui action there.


Below is the snapshot for reference.




UI Action form.jpg





Raj


View solution in original post

22 REPLIES 22

Hi!


I tried my best but can't quite get there.



UI Action Condition: gs.hasRole('itil') && !new ChangeRequestStateHandler(current).isOnHold() && new ChangeRequestStateHandler(current).isNext("closed") && ChangeTasks.activeTasks('false')



Script include name: ChangeTasks


Accessible from: All application scopes


Active: Yes


Script:


var ChangeTasks = Class.create();


ChangeTasks.prototype = {


  activeTasks: function() {



  var chg = new GlideRecord('change_request');


  var tsk = new GlideRecord('change_task');



  chg.get(current.sys_id);



  tsk.addAggregate('COUNT');


  tsk.addQuery('change_request',current.sysid);


  tsk.addActiveQuery();


  tsk.query();



  var count = 0;


  if (tsk.next()){


  count = tsk.getAggregate('COUNT');


  }



  if (state == 0 && type == 'emergency' && count > 0){


  return true;


  }


  else {


  return false;


  }


  },



  type: 'ChangeTasks'


};


let me just throw down a quick example.



I only only want this UI Action to be visible if the incident doesn't have any active incident childs



UI Action condition:   getChildInfo(current.sys_id);



Script include:



find_real_file.png



now this UI actions hides if the incident have any active childs and shows if it doesn't have any.



//Göran


I tried but this is not working.


Midhun1
Giga Guru

Yes UI Action is the best way to do this.


IamAmolB
Tera Guru

Thank you so much guys. It is working now and its working fine.
thank you so much all for your help