Problem with UI-action working together with UI-policy

pelleitaby
Giga Contributor

Hi!

I have created a button in a UI-action that takes the user to the next state in the change form. It work fine with a simple script checking the current state an then ad current plus one(1).

// This UI Action ensure that users are going to the next state in the process.

current.state = current.state + 1;

current.update();

action.setRedirectURL(current);

The problem i have is that no one of my UI policys, setting a lot of mandatory fields, works. The UI-action seems to go below the radar. As long as I use the button no fields sets to mandatory. If I change state manually the UI-policies work fine and sets the mandatory field as a want.

If anyone out there have any ideas i would be truly glad. Also se my two attachments.

Regards

Pelle

3 REPLIES 3

jesusemelendezm
Mega Guru

Hello Pelle,



If you are using a UI action, why don't you check right there on the script of the UI action if the fields are empty?? If they are empty then do not   go to the next step of the change. You can use client script in the UI action ?



This example UI action can help you create the one for your current scenario.



find_real_file.png



function resolveIncident(){


    //Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields


    g_form.setValue('incident_state', 6);


    g_form.setValue('state', 6);


//alert ("Missing mandatory fields");


    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 required when resolving an Incident','error');


          alert ("Missing mandatory fields");


          return false;   //Abort submission


    }


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


    gsftSubmit(null, g_form.getFormElement(), 'resolve_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')


    serverResolve();



function serverResolve(){


    current.incident_state = 6;


    current.update();


}



Mark as helpful or correct if this helps!



Regards.


joshua_bice
Giga Expert

Is your UI Policy set to run On Load?


Yes absolutely.






Per Sahlin


Koncerngemensamma system (KGS)



Axfood IT AB


Telefon: + 46 (8) 553 99 462


Mobil: +46 (70) 638 38 59


E-post: per.sahlin@axfood.se<mailto:jonas.broms@axfood.se>



Besöksadress: Norra stationsgatan 80 C


Postadress: Solnavägen 4, 107 69 Stockholm


Webb: www.axfood.se




<http://www.facebook.com/axfoodkoncernen> <http://www.twitter.com/axfood> <https://www.linkedin.com/company/axfood>


P Tänk på miljön innan du skriver ut <http://www.instagram.com/axfood_official>


<http://www.instagram.com/axfood_official>



19 nov. 2015 kl. 20:44 skrev joshua.bice <community-no-reply@servicenow.com<mailto:community-no-reply@servicenow.com>>:



ServiceNow<https://community.servicenow.com/?et=watches.email.thread>



Problem with UI-action working together with UI-policy



svar från Joshua Bice<https://community.servicenow.com/people/joshua.bice?et=watches.email.thread> i Developer Community - Visa hela diskussionen<https://community.servicenow.com/message/857712?et=watches.email.thread#857712>