restrict form submission on submit if no answer is returned by server site call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 11:28 AM
Hi All,
I have an OnSubmit catalog client script where I want to restrict the form submission if answer is not returned by server site call..
Have tried with scratchpad as well as NOW object ... it's not working... can anyone please suggest something on this...
Client Script code:-
function onSubmit() {
var actionname = g_form.getActionName();
if (NOW.u_isFormValid) {
return true;
}
var loc = g_form.getReference('location', getLoc);
var user = g_form.getReference("username", getUser);
var region;
var hyperion_code;
function getLoc(loc) {
region = loc.u_region;
var group_name = region + '-IMAC Requestors - Hardware';
if (region == "") {
alert(getMessage('HW Region Error'));
//return false;
NOW.u_isFormValid = true;
g_form.submit(actionName);
} else if (hyperion_code == "") {
alert(getMessage('HW Hyperion code Error'));
g_form.submitted = false;
return false;
} else {
var ga = new GlideAjax('CFHardwareApproverChecker');
ga.addParam('sysparm_name', 'ajax_hasApproversForHyperion');
ga.addParam('sysparm_hyperion_code', hyperion_code);
ga.addParam('sysparm_group_name', group_name);
ga.getXMLAnswer(chkHWAppError);
return false;
function chkHWAppError(response) {
//var ans = ga.getAnswer();
alert(response);
if (response != "true") {
alert(getMessage('HW Approver Error'));
return false;
}
// var actionName = g_form.getActionName();
// alert(actionName);
NOW.u_isFormValid = true;
g_form.submit(actionName);
}
//return true;
}
}
function getUser(user) {
hyperion_code = user.u_hyperion_code;
}
}
And Script Include:-
var CFHardwareApproverChecker = Class.create();
CFHardwareApproverChecker.prototype = Object.extendsObject(AbstractAjaxProcessor,
{
ajax_hasApproversForHyperion: function()
{
var hyperion_code = this.getParameter('sysparm_hyperion_code');
var group_name = this.getParameter('sysparm_group_name');
return this.hasApproversForHyperion(hyperion_code, group_name);
},
hasApproversForHyperion: function(hyperion_code, group_name)
{
var approvers = this.getApproversForHyperion(hyperion_code, group_name);
return approvers.length != 0;
},
isApproverForHyperion: function(hyperion_code, group_name, user_sys_id)
{
var approvers = this.getApproversForHyperion(hyperion_code, group_name);
for( var i = 0; i < approvers.length; i++)
{
if( approvers[i] == user_sys_id )
{
return true;
}
}
return false;
},
getApproversForHyperion: function(hyperion_code, group_name)
{
var ret = [];
var hccheck = new GlideRecord('u_user_hyperion_codes');
hccheck.addQuery('u_hyperion_code.u_hyperion_code', hyperion_code);
hccheck.addQuery('u_user.active', true);
hccheck.query();
while( hccheck.next() )
{
var user = gs.getUser().getUserByID(hccheck.u_user.sys_id);
if( user.isMemberOf(group_name) )
{
ret.push( hccheck.u_user.sys_id );
}
}
//gs.log("Hardware Request SI " +ret);
return ret;
},
type: 'CFHardwareApproverChecker'
});
@Ankur Bawiskar @Abhineet Singh @Anand Khurana @Manisha Sharma can you please suggest something on this.
Regards,
Nisha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 08:16 PM
so what's the issue and what debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 09:51 PM
Hi Ankur,
We tried with submitting the forms after using NOW object as well as scratchpad. But the form submission is not getting restricted.
Our requirement here is to restrict form submission until answer is received.
Can't use getXMLWait() because it's not supported on portal.
Hence, found an alternative to use getXMLAnswer() where we need to restrict form submission to wait for answer.
Can you please help me in getting this sorted 😞
Regards,
Nisha