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

apoorvmehta
Kilo Expert

We have a ui Action "Close Task" , which we need to make visible to the assignee or his delegate.

For this we are trying to call a script include which checks if the current logged in user is the assignee's delegate.

But the problem is that we are not able to call the script include from the "conditions" section of the ui action.

------------------------------------------------

Ui Action Condition:
javascript:delegateclosetasks()

------------------------------------------

Script Include Name - delegateclosetasks

Active - true

Client Callable - true

var delegateclosetasks = Class.create();

delegateclosetasks.prototype = {

      initialize: function() {

  gs.log("Entered Script Include","Apoorv");

//Check visibility conditions

  if(current.state !=3 && current.state !=4 && current.approval != 'requested' && (gs.getUser().isMemberOf(current.assignment_group.name)|| gs.getUser().isMemberOf('Change Analyst')) && current.change_request.state != 35)

  {

  gs.log("Entered if","Apoorv");

  return true;

  }

      },

      type: 'delegateclosetasks'

}

Somehow, I am not able to trigger the SI itself, before I can add the logic for checking delegate.

1 ACCEPTED SOLUTION

Conditions: new delegateclosetasks().allowdelegate();



1. You don't need the 'javascript' declaration in a condition field. It's already evaluated as JavaScript.


2. You forgot the () on your constructor call.


3. I don't think you need to check the 'client callable' box on your script include. It doesn't extend GlideAjax, and the condition field is evaluated on the server side.


View solution in original post

8 REPLIES 8

Hello Arpoov,


I am trying to call a script include from the condition of my UI action, but it does not work. I also tried to follow the tips above but seems i am ming someting, Could you please help me to get this issue solved ?



Here is my Ui action condition :


        new isUserFromRosenberg.checkUser();



Here is my script include (which I think is not being called)


var isUserFromRosenberg = Class.create();


isUserFromRosenberg.prototype = {



      checkUser: function() {


     


              //var UserRosenbergID     = this.getParameter('sysparm_userid');


             


              var us = new GlideRecord('sys_user');


              us.addQuery('sys_id', gs.getUserID());


              //us.addQuery('sys_id', UserRosenbergID);


              gs.log('gs.getUserID() : ' + gs.getUserID());


              var qc = us.addQuery('company.name', 'CONTAINS', 'Rosenberg');


              qc.addOrCondition('u_business_unit.name', 'CONTAINS', 'Rosenberg');


              us.query();


              if (!us.next()) {


                      return false;


              } else {


                      return true;


              }


      },


     


      type: 'isUserFromRosenberg'


};



Could me please help me to find out what wrong in the scripts ?


AKb Zic,



You're missing the parentheses on your Constructor call in the Condition field of the UI Action:



It should be: new isUserFromRosenberg().checkUser();


I saw my error, i forgot the '()' in my constructors (sorry i missread your advice in the first place!!)


to find this out, i took me 1hour !! I hate coding now !!


Thank you very much to you


It might be 5 years old but it still works. Thank you.