Increase the Max Length hof Condition in UI Action

thisisauniqueus
Giga Expert

Hi ,

Just wondering if its ok to increase the Max Length of Condition field in the UI Action?

find_real_file.png

Regards

1 ACCEPTED SOLUTION

Hi John,



For easier maintainability, keep the condition as short as possible. If the computation is complex, it is difficult to read and understand. Rather than increasing the field length, consider putting your logic in a script include. For example, rather than something like this...



current.active && current.canRead() && (current.state == 4 || current.state == 5 || current.state == 7) && (current.u_requester.department.getDisplayValue == 'Marketing' || current.u_requester.getDisplayValue() == 'HR') || gs.hasRole('admin')



It could look something like this:



new myConditionCheck().ApprovalUIAction(current);



and your script include becomes a thing of beauty to maintain and extend.



var myConditionCheck = Class.create();


myConditionCheck.prototype = {


      initialize: function() {


      },



  ApprovalUIAction : function(gr) {


  var isAdmin = gs.hasRole('admin');


  var canRad = gr.canRead();


  var isActive = gr.active;


  var isGoodState = (gr.state == 4 || gr.state == 5 || gr.state == 7);


  var dept = gr.u_requester.department.getDisplayValue();


  var isGoodDept = (dept == 'Marketing' || dept == 'HR');



  if (isActive && canRead && isGoodState && isGoodDept || isAdmin)


  return true;



  return false;


  },



      type: 'myConditionCheck'


};



Andrew and I covered this in our video a while back:


Script Includes


View solution in original post

13 REPLIES 13

Mihir Mohanta
Kilo Sage

I suggest to call a script include from the condition field   instead of increase length of this field.



Thanks,


Mihir


how to do that?

 

Build out the complex logic in a Script include function to return a truthy or falsy answer. Example:

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

    myFunction : function(gr) {

        // gr is a GlideRecord, typically 'current' from the UI action condition
        // now you have access to a lot of valuable information in one nice package
        // Your function also has access to all the other server-side objects like
        // GlideSystem (ex: gs.getUser), GlideAggregate, etc.
        // Do some special logic here and return true/false

        return true;
    },

    type: 'myConditionCheck'
};

In the UI action condition, it would be called like this:

new myConditionCheck().myFunction(current);

If the function returns true, your UI action is presented on the screen and you can run it with a click. If it returns false, no UI action is shown.

Mihir Mohanta
Kilo Sage

Hi John,



Please go through below thread.You will get idea how to call script include from condition of ui action.



How to call script include from the "condition" section of a UI Action?



Thanks,


Mihir