Ignore mandatory fields while submitting a form in Agent Workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 02:51 PM
Hi,
I'm trying to update the "Assign to me" button in Agent Workspace, so that it will change the assigned_to value to the current user even if they haven't filled out the mandatory fields on the form. The fields are set as mandatory through the dictionary reference, for example:
On a standard platform form, I can succesfully save the form by calling g_form.checkMandatory = false; before saving, but this property doesn't seem to be available in Workspace according to this document.
I've worked around this by using the following client script, but it's quite slow (takes a second for all field items to be iterated through, and also the form jumps around a little bit as the '*'s are removed), and I was wondering if there's a better way to do it:
function onClick(g_form) {
g_form.setValue('assigned_to', g_user.userID);
// set all fields as not mandatory
var allFields = g_form.getFieldNames();
for (var fieldName in allFields){
g_form.setMandatory(allFields[fieldName], false);
}
g_form.submit('sysverb_ws_save');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 03:26 PM
You can use g_form.getMissingFields(); to get all fields that are mandatory, then deactivate them. That'll at least cut the number of fields it is churning through. But, this is how I have done it in the past, so I don't know of a better method, just a more efficient method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 04:39 PM
Hi Mike, I'd seen other people mention that function, but didn't see it in the list of supported client-side APIs, so I hadn't tried it: https://docs.servicenow.com/bundle/madrid-servicenow-platform/page/build/service-portal/reference/cl...
I've just tested it now, and unfortunately it seems that it's not available in Workspace:
SCRIPT:EXEC Error while running Client Script "GlideScopedScript": TypeError: g_form.getMissingFields is not a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2021 08:35 AM
This won't work in Agent Workspace
When going to the browser debugger, the console show an error "g_form.getMissingFields is not a function"
This is all I put in the Workspace Client Script:
var arr = g_form.getMissingFields();
We're currently on Quebec Patch 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2021 09:16 AM
You can try below code on UI action. It will work.
function callClientScript() {
//Client Script
var arr = g_form.getMissingFields();
for (var x = 0; x < arr.length; x++) {
g_form.setMandatory(arr[x], false);
alert("Following fields are set Non Mandatory: " + arr[x]);
}
gsftSubmit(null, g_form.getFormElement(), 'update_to_p1'); // UI action name
}
if (typeof window == 'undefined')
callServerScript();
function serverScript() {
// Server Script
current.update();
action.setRedirectURL(current);
}
Please mark answer helpful if it helped.
Regards
Pawan K Singh