From e718f6e284969efda4c63a5a5fafe748baa3fe03 Mon Sep 17 00:00:00 2001 From: Dimitri Iordanidis Date: Tue, 3 Oct 2023 12:53:51 +0200 Subject: [PATCH 1/3] Create readme.md --- .../Open modal widget in an Onsubmit/readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Catalog Client Script/Open modal widget in an Onsubmit/readme.md 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..a842fd55c6 --- /dev/null +++ b/Catalog Client Script/Open modal widget in an Onsubmit/readme.md @@ -0,0 +1,3 @@ +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. + +A use case might be to check for active cases of the logged-in user. If there is an active case for the same HR service he is trying to submit the case for we can stop the submission of the record producer and showcase in the widget a list of all the active cases of that user. In that way, we can prevent duplication in a user-friendly way. From 6c6c5b0de6a48864c093e107e0f39bf3b5085864 Mon Sep 17 00:00:00 2001 From: Dimitri Iordanidis Date: Tue, 3 Oct 2023 13:22:38 +0200 Subject: [PATCH 2/3] Create openmodal.js --- .../openmodal.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Catalog Client Script/Open modal widget in an Onsubmit/openmodal.js 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; + } From d0a11ae42a31944be6bc693ba8b128e1cbf0e75f Mon Sep 17 00:00:00 2001 From: Dimitri Iordanidis Date: Tue, 3 Oct 2023 13:23:19 +0200 Subject: [PATCH 3/3] Update readme.md --- .../Open modal widget in an Onsubmit/readme.md | 2 -- 1 file changed, 2 deletions(-) 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 index a842fd55c6..d62aa88289 100644 --- a/Catalog Client Script/Open modal widget in an Onsubmit/readme.md +++ b/Catalog Client Script/Open modal widget in an Onsubmit/readme.md @@ -1,3 +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. - -A use case might be to check for active cases of the logged-in user. If there is an active case for the same HR service he is trying to submit the case for we can stop the submission of the record producer and showcase in the widget a list of all the active cases of that user. In that way, we can prevent duplication in a user-friendly way.