Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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.