onSubmit script g_modal popup saving form when popup appears
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 02:39 AM
Hello,
I have the following onSubmit client script, and it presents a modal popup for end users when conditions are met.
This is for native Ui and agent workspace.
Works fine in native, it prompts the user with modal and only submits form when user selects yes.
Whereas in workspace, when the modal popup appears the form saves at the same time.
How can I prevent the form from saving in workspace until the modal has not been actioned, i.e. yes/no selected.
here is my script for HR cases:
function onSubmit() {
var subjectPersonValue = g_form.getValue('subject_person');
var openedForValue = g_form.getValue('opened_for');
var openedFor = g_form.getControl('opened_for');
var url = top.location.href;
if (url.indexOf('workspace') <= -1) { // if using native UI run this code
if (openedFor.changed) {
if (subjectPersonValue == openedForValue) {
if (g_scratchpad._action_confirmed) {
return true;
}
// Render GlideModal window
var dialog = new GlideModal('glide_modal_confirm', false, 400);
dialog.setTitle(new GwtMessage().getMessage('Opened for Changed to Subject Person'));
dialog.setPreference('body', new GwtMessage().format("You have set the Opened For to the Subject Person, which will grant them access to view the Case - are you sure?"));
dialog.setPreference('focusTrap', true);
dialog.setPreference('onPromptComplete', doComplete);
dialog.setPreference('onPromptCancel', doCancel);
dialog.render();
return false;
function doComplete() {
g_scratchpad._action_confirmed = true;
gsftSubmit(null, g_form.getFormElement(), g_form.getActionName());
}
function doCancel() {
}
}
}
} else if (url.indexOf('workspace') > -1) { // if using workspace run this code
if (g_scratchpad.openedFor != g_form.getValue('opened_for')) { // If opened for value has changed
if (subjectPersonValue == openedForValue) {
// Render Modal window
var msg = "You have set the Opened For to the Subject Person, which will grant them access to view the Case - are you sure?";
g_modal.confirm(getMessage("Opened for Changed to Subject Person"), msg, function(confirmed) {
if (confirmed) {
g_form.save();
}
});
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 02:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 03:02 AM
I removed the .uniqueValue statements from the code and now not getting error.
Although the logic for checking if the subject person has access to the case does not seem to be working.
I tested using a case where I set the subject person same as the Opened by.
I then changed the opened for to match the subject person, at which point I received the modal confirm box.
But it should not appear if the subject person is also the opened for or opened by.
Please help resolve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 03:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 05:15 AM
Removing that from code is not the solution. That just ensures that the code will not work. You need to make sure the display business rule is correctly configured and does add the required information to the scratchpad.