Skip to content

Commit 1db5eeb

Browse files
authored
Open modal widget onsubmit (ServiceNowDevProgram#716)
1 parent 36e496f commit 1db5eeb

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
function onSubmit() {
2+
3+
4+
if (g_scratchpad.isFormValid)
5+
return true;
6+
7+
//We can do some check using a Client Callable script include
8+
var getAnswer = new GlideAjax('example');
9+
getAnswer.addParam('sysparm_name', 'checkFor');
10+
getAnswer.addParam('sysparm_input1', g_user.userID);
11+
getAnswer.addParam('sysparm_input2', g_form.getUniqueValue());
12+
13+
getAnswer.getXML(parsing);
14+
15+
function parsing(response) {
16+
17+
var answer = response.responseXML.documentElement.getAttribute('answer');
18+
if (answer) {
19+
var data = JSON.parse(answer);
20+
21+
if (data == true) {
22+
23+
spModal.open({
24+
title: "Test title",
25+
widget: "mywidget",
26+
buttons: [{
27+
label: 'Close',
28+
value: 'close'
29+
},
30+
{
31+
label: 'Create New Record',
32+
value: 'create'
33+
}
34+
],
35+
size: 'md'
36+
}).then(function(answer) {
37+
//if button pressed is "create" then submit the form
38+
if (answer.value == 'create') {
39+
g_scratchpad.isFormValid = true;
40+
g_form.submit();
41+
}
42+
});
43+
} else {
44+
g_scratchpad.isFormValid = true;
45+
g_form.submit();
46+
}
47+
48+
}
49+
50+
}
51+
//Dont submit the form
52+
return false;
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)