UI Action not executing both client and server side script at same time

BharathKumar00
Tera Contributor

Hi,
I am trying to make a field mandatory using a client side function and setting another field to current date in server side function in a UI Action named review complete. When I click on the UI action link, the client side script is working and making the review notes field as mandatory but the client side script is not working. 
Server side script is only working when I click on the review complete UI action link twice i.e
--> On the first click, the alert is displayed and it is making review notes mandatory and I'm populating something.
--> On second click it is again giving the alert and now as I have populated something, the form is reloading and the          review date field is also being set to current date.

I need both of them to execute on the first click of UI action link. How to achieve this? Following is the script I have written in UI action

function makeMandatory(){
alert("client");
if(g_form.getValue('review_notes')== ''){
g_form.setMandatory('review_notes',true);
return false;
}

gsftSubmit(null, g_form.getFormElement(), 'review_complete');
}
callserverside();

function callserverside(){
    gs.addInfoMessage('Inside server');
    var d = GlideDateTime().getDate();
    current.review_date = d;
action.setRedirectURL(current);
}

2 REPLIES 2

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @BharathKumar00 ,

I did modification in code, I didn't tested but give it a try it shoul work. 

 

function makeMandatory(){
alert("client");
if(g_form.getValue('review_notes')== ''){
g_form.setMandatory('review_notes',true);
return false;
}

gsftSubmit(null, g_form.getFormElement(), 'review_complete');
}

 

if (typeof window == 'undefined') {
  gs.addInfoMessage('Inside server');
    var d = GlideDateTime().getDate();
    current.review_date = d;
action.setRedirectURL(current);
}
 
 

Kindly mark my answer as Correct and helpful based on the Impact.

Regards,

Siddhesh

 

 

Anand Kumar P
Giga Patron
Giga Patron

Hi @BharathKumar00 ,

I updated below it will work
Onclick-makeMandatory()
Action name-review_complete

 

//Client-side 'onclick' function
function makeMandatory(){
alert("client");
if(g_form.getValue('review_notes')== ''){
g_form.setMandatory('review_notes',true);
return false;//abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'review_complete');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')//added
callserverside();
function callserverside(){
    gs.addInfoMessage('Inside server');
    var d = new GlideDate();//added new
    current.review_date = d;//review_date assuming its a date filed
current.update();///added 
action.setRedirectURL(current);
}

 

Mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand