UI Action not executing both client and server side script at same time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 03:06 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 07:59 AM
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');
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2023 09:18 AM - edited ‎12-07-2023 09:21 AM
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