can someone help me to userstand UI action how its working client and server side together with example ..?

s_kumar
Mega Contributor

Request

1 ACCEPTED SOLUTION

zica
Giga Guru

Okay perfect,



Here is a screenshot that shows the parameters of the UI action, Please do the same


Do not forget to put the action name, check client to true, and put the function name on Onclick()


Capture d



HEre is the script :



function reopenIncidentTest(){


     


      if (g_form.getValue('comments') == '') {


              //Remove any existing field message, set comments mandatory, and show a new field message


              try {


                    g_form.hideFieldMsg('comments');


              } catch(e) {}


                    g_form.setMandatory('comments', true);


                    g_form.showFieldMsg('comments','Reason is required when reopening an incident','error');


                      return false;   //Abort submission


        }


      //Call the UI Action and skip the 'onclick' function


      gsftSubmit(null, g_form.getFormElement(), 'incident_reopen_test'); //MUST call the 'Action name' set in this UI Action


}



//Code that runs without 'onclick'


//Ensure call to server-side function with no browser errors



if (typeof window == 'undefined')


      serverReject();



function serverReject(){


      current.state = 2;


      current.update();


}


View solution in original post

31 REPLIES 31

s_kumar
Mega Contributor

Hi arnab,


I iam trying the same but its not working please check ...



condition :         current.state == 6 && current.short_description =="helloooo"




Script:



//Client-side 'onclick' function


function reopen(){


    if(g_form.getValue('comments') == ''){


          //Remove any existing field message, set comments mandatory, and show a new field message


          g_form.hideFieldMsg('comments');


          g_form.setMandatory('comments', true);


          g_form.showFieldMsg('comments','Comments are mandatory when reopening an Incident.','error');


          return false;   //Abort submission


    }


    //Call the UI Action and skip the 'onclick' function


    gsftSubmit(null, g_form.getFormElement(), 'reopen_incident'); //MUST call the 'Action name' set in this UI Action


}



//Code that runs without 'onclick'


//Ensure call to server-side function with no browser errors


if(typeof window == 'undefined')


    serverReopen();



function serverReopen(){


    //Set the 'State' to 'Active', update and reload the record


    current.state = 2;


    current.update();


    gs.addInfoMessage('Incident ' + current.number + ' reopened.');


    action.setRedirectURL(current);


}




please check where i am missing what ..';


Kumar,



Change this from current.state == 6 to current.state == '6'


Same for this one as well from       current.state = 2 to       current.state = '2';



Note : Please ensure that you put the correct value of the state... Sometimes it is integer, sometimes string (depends where and your instance was set up).


To make sure, open the form you are working on (e.g incident, change, pb, etc...) and right click on the state field on that form.


Then Dictionary. A new form will open, scroll down, go to "choice list" tab and take the character you have under "value" column of the state.


s_kumar
Mega Contributor

Hi Zic



I tried this also its not changing the state from resolved to Active..!!


Hi Sandeep,



Please compare the below ui action code for my Re-open incident button. Make the necessary changes. Also as said by Zic please check the values of fields carefully.


123.PNG



The Code:


1234.PNG



Thanks,


Arnab



Please let me know your reply


s_kumar
Mega Contributor

Hi Arnav,



i have used your same code ...


//Client-side 'onclick' function


function reopen(){



    if(g_form.getValue('comments') == ''){


          //Remove any existing field message, set comments mandatory, and show a new field message


      try


      {


          g_form.hideFieldMsg('comments');


      }catch(e) {}


          g_form.setMandatory('comments', true);


          g_form.showFieldMsg('comments','Comments are mandatory when reopening an Incident.','error');


          return false;   //Abort submission


    }


    //Call the UI Action and skip the 'onclick' function


    gsftSubmit(null, g_form.getFormElement(), ' reopen'); //MUST call the 'Action name' set in this UI Action


}



//Code that runs without 'onclick'


//Ensure call to server-side function with no browser errors


if(typeof window == 'undefined')


    serverReopen();



function serverReopen(){


    //Set the 'State' to 'Active', update and reload the record


    current.state = '2';


    current.update();


    gs.addInfoMessage('Incident ' + current.number + ' reopened.');


    action.setRedirectURL(current);


}



but its not changing the state ... even i implemented Zic help also ..