Adding a wait condition to a ui action

Sam Motley
Giga Guru

Hi All, 

 

I've trying to add a wait condition to a UI policy to allow a workflow to complete before the page is refreshed 

i have tried gs.sleep(); which worked in our test instance but not in production 

 

although after further investigation i've found this is not the best practice. 

Has anyone had any experience adding a wait for 5 seconds or so before redirecting to the current page? 

 

UI Action: 

Name: Submit

Table: Change_request

order: 100

script:

answer = current.insert();


gs.include('ActionUtils');


var au = new ActionUtils();


au.postInsert(current);


gs.sleep(4500);
action.setRedirectURL(current);

 

cheers 

1 ACCEPTED SOLUTION

Use a UI policy instead

 

Mike_R_0-1669821668988.png

 

Mike_R_1-1669821684525.png

 

But also with that being said, your script is using GlideRecord in a client side code. While this will work, best practices (for performance reasons) is to use GlideAJAX/client callable script include instead.

 

View solution in original post

9 REPLIES 9

Any particular reason why you can't use the OOTB conflict detection? The you can create a  before update business rule to automatically change the type to emergency if a conflict is found

 

Mike_R_0-1669820872470.png

 

Hi Mike, we are using this is how the conflict is found initially 

it's just because there's a few seconds delay the conflict takes a few secs to appear and my blackout notification is based on the conflict being present 

Please find below the script: 

 

function onLoad() {

var conflicts = new GlideRecord('conflict');

var sys = g_form.getUniqueValue();

conflicts.addQuery('change', sys);

conflicts.addQuery('type', 'blackout');

conflicts.query();

if (conflicts.hasNext()) {

g_form.addInfoMessage('<font color="red">THIS CHANGE HAS BEEN RAISED DURING A CHANGE FREEZE</font>');

if(g_form.getValue('u_emergency') == 'No'){
g_form.addInfoMessage('<font color="red">THIS CHANGE HAS BEEN SET TO EMERGENCY, PLEASE REVIEW AND SUBMIT</font>');
g_form.setValue ("u_emergency","Yes");
alert("RED ALERT – This change has been raised during a CHANGE FREEZE");

}
}

}

Use a UI policy instead

 

Mike_R_0-1669821668988.png

 

Mike_R_1-1669821684525.png

 

But also with that being said, your script is using GlideRecord in a client side code. While this will work, best practices (for performance reasons) is to use GlideAJAX/client callable script include instead.

 

Thanks Mike really appreciate the assist

Rick52
Tera Contributor

Tried this and it worked. Update the fields that need to be updated first, then do a second update with the "setWorkflow(false)". See my script below

var gr_inc_resolved = new GlideRecord('incident');
gr_inc_resolved.addEncodedQuery(query_inc_resolved);
gr_inc_resolved.query();

while (gr_inc_resolved.next()) {
    gr_inc_resolved.u_state_reason = "QA Verified Successful";
	gr_inc_resolved.work_notes = "Incident is auto closed after 7 days";
	gr_inc_resolved.update();
	gr_inc_resolved.state = 7; // Closed
	gr_inc_resolved.setWorkflow(false);
    gr_inc_resolved.active = false;
    gr_inc_resolved.update();
}