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

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


Thanks alot Chuck!



Regards


You are welcome John. I turn to that solution any time I get more than three or four conditions (&& and ||) strung together, or have to make a GlideRecord query. Too hard to read as one line, but a clear, concise function call is (usually) more readable later.


simply brilliant.  Thanks Chuck!

Thanks, Chuck! We are in the process of making a change in how we process Identity Access Management requests. Part of the process included creating a new catalog item. We have a UI macro that allows for the restart of the workflow from the RITM list view that is restricted to admins and the IAM team, and the request was cancelled by a service account. Adding the second cat_item was too much for the field. This is what I came up with.

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


    retartIDNTerm: function(gr) {
        var catItem = gr.cat_item.toString();
        var isAdmin = gs.hasRole('admin');
        var isIAM = gs.hasRole('x_sap_intidn.requestable_objects_user');
        var isCancelled = (gr.stage == 'request_cancelled' || gr.stage == 'Request Cancelled');
        var catItemIAR = (catItem == '45b7028f976f819cfe4b75600153af76');
        var catItemMAR = (catItem == '924fc27397384e90fe4b75600153af44');
        var closedBy = (gr.closed_by == '8a3c9423db338018cc696cf3ca9619b5');
        if ((isIAM || isAdmin) && isCancelled && closedBy && (catItemMAR || catItemIAR))
            return true;
        return false;
    },

    type: 'mcyConditionCheck'
};