How to make Two fields mandatory on clicking Close UI action button?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2021 12:54 AM
Hi All,
I want to make two fields mandatory when user clicks on Close UI action, as one of the fields is Additional comments, I can't go with data policy, because if I give a condition like Make comments mandatory in close state, comments is mandatory even after the ticket gets closed. I want the fields to become mandatory only on clicking the UI action. I have written the below code, but it is working like one after the other If condition. i.e., if I click on Close for first time, it is showing comments mandatory. After filling comments, if I click on the button again, then it is showing track number mandatory.
function closeRequest(){
if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
//g_form.hideFieldMsg('comments');
g_form.setMandatory('comments', true);
g_form.addErrorMessage('The following mandatory fields are not filled in: Additional Comments');
return false; //Abort submission
}
else if (g_form.getValue('track_number') == ''){
g_form.setMandatory('track_number', true);
g_form.addErrorMessage('The following mandatory fields are not filled in: Track Number');
return false;
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_request'); //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')
updateTask();
function updateTask(){
current.state = 3;
current.update();
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2021 01:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2021 01:12 AM
Hi
I think if we use and condition, then if loop gets executed only when both are empty. If any of the fields have value, then it doesn't run. And also, how to display field name which is empty, in error message?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2021 01:27 AM
Hi Ajay,
Instead of 'else if', just try with IF. In that case both the if condition will be evaluated whenever the code runs. Let me know if it helps.
Regards,
Shishir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2021 01:32 AM
Hi
No Shishir, not working. Working like before itself.
Thank you.