List choice UI Action not working on client side.

Rohant Joshi2
Kilo Expert

Hello All,

 

I got a small requirement to close all the Incidents in one go, for that I create a List choice UI action. Problem I am facing is as we know for List choice the code will execute as much times as much records are selected from the list view.

 

Just to give some good user interactive view I tried giving up the pop up before user executes the code of UI Action. But in that case my code is not working.

Here I am putting snippet :

action name is : force_close

client callable : true

 

function onForceCloseClick()

{

    var conf = confirm("Are you sure you want to close all the selected incidents?");

    if(conf==false)

          return false;

         

      gsftSubmit(null, g_form.getFormElement(), 'force_close');

 

}

 

      if(typeof window == 'undefined'){

      commitFC();

    }

 

function commitFC(){

    gs.log('Entering the commitFC');

    var sys_ids = action.get("sysparm_checked_items");

    //gs.log('Force Closure of Incident start... '+sys_ids);

    var inc = new GlideRecord('incident');

    inc.addQuery('company.name', 'ABC');

    inc.addQuery('active', true);

    inc.addQuery('caller_id.name','Proactive');

    inc.addQuery('incident_state', '!=', 7);   // closed = 7

    inc.addQuery('sys_id',current.sys_id);

    inc.orderBy('sys_created_on');

    inc.query();

      while (inc.next()) {          

      inc.incident_state = 7;      

      inc.update();

      gs.log('"UPDATE INCIDENT: updated ' + inc.number);

  }

}

 

Here, I have both client side and server side code, using above code I am able to get the pop up but it not progressing further.

And in case if I remove everything and keep just the server side code everything is working fine. I want to know is there any limitation for List Choice type of UI action where we can run both server and client side code simultaneously.

7 REPLIES 7

Thanks 

viktor.lukashov

It was very useful for me.

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya

shrutim
Kilo Contributor

Hello All,



I am facing the same problem which was faced by Rohant earlier but with change module.



My requirement is to close all the changes in one go   for a particular company and for other companies popup should   display .


I am getting the desired popup message , but change is not getting forced close when force closure is requested, instead state changes to "Open" and stage to "New".



Pasting my code snippet here:



client callable : true


onClick:   getList()



function getList(){


     


      var sys_ids = g_list.getChecked();


      var sys_id = sys_ids.split(",");


      //alert("sys ids=" + sys_ids);


      var cr = new GlideRecord('change_request');


     


      cr.addQuery('active', true);


      cr.addQuery('state', '!=', 5);   // closed = 5



     


      cr.addQuery('sys_id','IN',sys_ids);


      cr.orderBy('sys_created_on');


      cr.query();


      while (cr.next()){


             


              if(cr.company != 'company's sys_id')


          {


                      alert("Change Force Closure is not permitted for this customer");


                      return false;


              }


             


              else if(cr.company == 'company's sys_id')


                    {


                     


                      alert("force closure allowed");


             


                      cr.u_stage = 'Closed Completed';


                      cr.state = 5;


                      cr.update();


                      }


              }


     


}


Pratik Malviya
Tera Guru

g_list.action('[sys_id of the force_close UI action]', 'UI_action_name');

 

It is very useful when you want to create UI action type list choice and want to run client and server-side code.

 

# Name :- [###]

# Action Name : UI_ACTION_NAME

#Client = True

// Client side code

 

function confirmAndCreateProblem(){

var conf = confirm("Are you sure you want to create Problem for selected Incident ?");
if(conf){
g_list.action('SYS_ID Of UI Action', 'ACTION_NAME'); // [UI Action SYS_ID]
}
}

 

 

if(typeof window == 'undefined')
generateNewPO();

function generateNewPO(){

WRITE HERE YOUR SERVER SIDE CODE.


}

 

Please mark helpful.

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya