Problem with UI-action working together with UI-policy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2015 01:01 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2015 01:56 PM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2015 11:44 AM
Is your UI Policy set to run On Load?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2015 01:24 PM
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>