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

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

Where is this part of code:

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); }

 

In Workspace script or normal script box at top.

Thanks,
Ashutosh

I tried it in both workspace cs and normal cs but couldn't get this to work

in workspace cs I added it to after function onClick() { 

 

I don't even need to save the work I just want to leave the form and go to the new form that will open in workspace which as mentioned does happen when I click on this button with all mandatory fields completed

MrMuhammad
Giga Sage

try something like this. make all the fields non- mandatory before submiting the form. 

function onClick() {
  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);
  }

  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);
  });
}
Regards,
Muhammad

I tried this but didn't work 😞