Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Workspace client script UI action to open new form how can I supress mandatory fields on current form

Ellie2
Kilo Expert

Hi All

I am trying to tweak the UI action ->Workspace Client Script  below

with either g_form.checkMandatory = false; 

 or

for (var i = 0; i < g_form.elements.length; i++)
{
    var el = g_form.elements[i];
    var fieldName = el.fieldName;
    g_form.setMandatory(fieldName, false);
}

to make the mandatory fields on the form not mandatory so that on button click the new form opens. The below works when all mandatory fields are completed but I need it to work when the mandatory fields are still unanswered.

Any suggestions greatly appreciated. Thanks!

===================================

function onClick() {
var result = g_form.submit('sysverb_ws_save');

if (!result) {
//failed form submission
return;
}

result.then(function() {
var params ={};
params.sysparm_parent_table = "xxxxxxxxx";
params.sysparm_parent_sys_id = g_form.getUniqueValue();
g_service_catalog.openCatalogItem('xxxxxxx', '-1', params);
});
}

 

1 ACCEPTED SOLUTION

Ellie2
Kilo Expert

Solved it with using g_form.getFieldValues....  instead of

g_form.elements.length;

View solution in original post

7 REPLIES 7

Then there might be some fields made mandatory on dictionary level that's why its not allowing you to make them non-mandat.. 

Regards,
Muhammad

Hi Muhammad, I double check there are no dictionary level mandatory fields at all. All fields are made mandatory with UI policy on the form only.

 

 

Ellie2
Kilo Expert

Solved it with using g_form.getFieldValues....  instead of

g_form.elements.length;