diff --git a/Catalog Client Script/Open modal widget in an Onsubmit/openmodal.js b/Catalog Client Script/Open modal widget in an Onsubmit/openmodal.js new file mode 100644 index 0000000000..b3b9896e50 --- /dev/null +++ b/Catalog Client Script/Open modal widget in an Onsubmit/openmodal.js @@ -0,0 +1,53 @@ + function onSubmit() { + + + if (g_scratchpad.isFormValid) + return true; + + //We can do some check using a Client Callable script include + var getAnswer = new GlideAjax('example'); + getAnswer.addParam('sysparm_name', 'checkFor'); + getAnswer.addParam('sysparm_input1', g_user.userID); + getAnswer.addParam('sysparm_input2', g_form.getUniqueValue()); + + getAnswer.getXML(parsing); + + function parsing(response) { + + var answer = response.responseXML.documentElement.getAttribute('answer'); + if (answer) { + var data = JSON.parse(answer); + + if (data == true) { + + spModal.open({ + title: "Test title", + widget: "mywidget", + buttons: [{ + label: 'Close', + value: 'close' + }, + { + label: 'Create New Record', + value: 'create' + } + ], + size: 'md' + }).then(function(answer) { + //if button pressed is "create" then submit the form + if (answer.value == 'create') { + g_scratchpad.isFormValid = true; + g_form.submit(); + } + }); + } else { + g_scratchpad.isFormValid = true; + g_form.submit(); + } + + } + + } + //Dont submit the form + return false; + } diff --git a/Catalog Client Script/Open modal widget in an Onsubmit/readme.md b/Catalog Client Script/Open modal widget in an Onsubmit/readme.md new file mode 100644 index 0000000000..d62aa88289 --- /dev/null +++ b/Catalog Client Script/Open modal widget in an Onsubmit/readme.md @@ -0,0 +1 @@ +Code snippet to stop submission of a form in an Onsubmit Client Script, use an asynchronous call, and open a Widget in Modal view. In the script provided, there are two buttons in the modal. The first continues with the submission to create a new record and the second one cancels it. We can use a Script Include to get some value that we want and based on that open the modal or continue with submission.