How to call flow designer action from OnSubmit client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 11:02 PM
Hello,
From the Onsubmit Client script, I'm trying to trigger the Flow Designer action. But it is not working.
As you can see from the code below, I'm trying to call a flow designer action, and based on the output, if output is true, I need to send an error message and stop from submitting the request, and if output is false, it can submit the request. However, the code below is not working. Can somebody tell me what went wrong in the code below?
function onSubmit() {
//Type appropriate comment here, and begin script below
(function() {
var userID = g_form.request_For.sys_id;
var denyInternet = 'DENYINTERNETACCESS.LG';
var phising = 'PHISHING.DIA';
var inputs = {};
inputs['user_sys_id'] = userID; // String
inputs['group_name'] = denyInternet, phising; // String
GlideFlow.startAction('x_iem_iam.privisusermemberofgroup', inputs)
.then(function(execution) {
return execution.awaitCompletion();
}, errorResolver)
.then(function(completion) {
var status = completion.status;
// Available Outputs:
var outputs = completion.outputs;
var ismemberofgroup = outputs['ismemberofgroup']; // True/False
if (ismemberofgroup == false) {
return true;
} else {
g_form.addErrorMessage('You are part of the Phishing group which restricts access to internet. Please contact the CyberSecurity team for additional details');
return false;
}
});
function errorResolver(error) {
// Handle errors in error resolver
}
})();
}
Thanks,
JRY
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 11:25 PM
Hi,
why not use GlideAjax to validate this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 11:58 PM
I'm trying to call flow action from onsubmit client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 12:37 AM
Sorry for the late reply. I didn't get you. As per my understanding, do I need to call flow action on script include and call script include from the Onsubmit client script right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 12:42 AM
Hi Ankur,
Can you please help me what needs to be change on below code
Client side:
function onSubmit() {
//Type appropriate comment here, and begin script below
(function() {
var userID = g_form.requested_for;
var phising = ['DENYINTERNETACCESS.LG', 'PHISHING.DIA'];
var inputs = {};
inputs['user_sys_id'] = userID; // String
inputs['group_name'] = phising; // String
GlideFlow.startAction('x_iem_iam.privisusermemberofgroup', inputs)
.then(function(execution) {
return execution.awaitCompletion();
}, errorResolver)
.then(function(completion) {
var status = completion.status;
// Available Outputs:
var outputs = completion.outputs;
var ismemberofgroup = outputs['ismemberofgroup']; // True/False
if (ismemberofgroup == false) {
return true;
} else {
g_form.addErrorMessage('You are part of the Phishing group which restricts access to internet. Please contact the CyberSecurity team for additional details');
return false;
}
}, errorResolver());
function errorResolver(error) {
// Handle errors in error resolver
console.error(error);
}
})();
}
Server side:
(function() {
try {
var inputs = {};
inputs['user_sys_id'] = ; // String
inputs['group_name'] = ; // String
// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().action('x_iem_iam.privisusermemberofgroup').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().action('x_iem_iam.privisusermemberofgroup').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
// Get Outputs:
// Note: outputs can only be retrieved when executing synchronously.
var ismemberofgroup = outputs['ismemberofgroup']; // True/False
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();