UI Action redirect with alert

techies
Kilo Expert

Hi All,

I have a UI Action that redirects/refreshes itself like so,

        action.setRedirectURL(current);

I however wish to have an alert to the user g_form.addInfoMessage("here"); after the form has been refreshed. I can't do it before the redirect because the alert message just disappears once the page starts loading.

Is there anyway to alert the user and refresh the form?

Thanks for any help.

1 ACCEPTED SOLUTION

That is because you have that statement in the onClick function. onClick function runs on the client side, before the form is submitted. For the message to be displayed after the form reloads, you need to have that in the server function.



If all you are doing is redirecting, then there's no point in including Client functionality. Uncheck the Client checkbox and paste this code in the Script:



action.setRedirectURL(current);


gs.addInfoMessage('here');



But if you have some client code to be executed before the server code, then it should be something like this:



//Client-side 'onclick' function


function onClick(){


  // client side code goes here


 


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


}




//Code that runs without 'onclick'


if(typeof window == 'undefined')


  serverCode();




function serverCode(){


      action.setRedirectURL(current);


      gs.addInfoMessage('here');


}


View solution in original post

6 REPLIES 6

veena_kvkk88
Mega Guru

Hi Roni,



I'm pretty sure that the script is executed sequentially. If you place the statement printing the message after the redirect statement, the message pops up after the page is reloaded.



action.setRedirectURL(current);


gs.addInfoMessage('After Reload');



You would be using gs since g_form doesn't work in Server side scripts.


Hi,


gs.addInfoMessage does not seem to work in UI actions. It wont submit the form. g_form does work it was built for UI actions, it just outputs then reloads the page so it disappears.


gs is a server side object, so it only works in Server code. But if the UI action is made of both client and server code, it's different.



Did my solution work? If not, would you mind sharing your whole script? It helps to better understand where the issue is.


It didn't work.


In my onClick function I have this,


          g_form.addInfoMessage('here');


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



'here' is displayed while the form is loading but then disappears after load.