How to make mandatory fields save while checking for attachments in UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 08:02 AM
Hello All! I have a requirement to check for multiple mandatory fields as well as attachments before a state is updated. I have the UI Action working properly, but it is not ideal from a user perspective. On the actual business requirement there are 10+ mandatory fields for the user to fill out. My problem is, when you click on the UI action if you have filled out the mandatory fields, but NOT attached a document, all of the mandatory fields are being reset. In my example in my PDI I only have two fields for test purposes. My question is, is there a way to get the answers for the mandatory fields to persist without updating the state?
This is with the mandatory fields filled out before the UI Action button is clicked.
This is an image of AFTER the UI button is clicked. As you can see from my image, the two mandatory fields have been reset. This is not ideal, as in my business requirement, we have 10+ fields that are being reset and this is not user friendly.
Below is my UIAction code:
function changeState() {
if (g_form.getValue('u_create_and_assigned' && 'test_field') == "") {
g_form.setMandatory('u_create_and_assigned', true);
g_form.setMandatory('test_field', true);
g_form.showFieldMsg('u_create_and_assigned', "Please select an answer before changing the state.");
g_form.showFieldMsg('test_field', "Please select an answer before changing the state.");
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'check_fields');
}
if (typeof window == 'undefined')
serverReopen();
function serverReopen() {
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments(current.getTableName(), current.sys_id);
if (agr.next()) {
current.state = 2;
current.update();
action.setRedirectURL(current);
} else {
gs.addErrorMessage('You must add an attachment before moving to the next state!');
action.setRedirectURL(current);
}
action.setRedirectURL(current);
}