Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Issue with g_form.elements.length in UI Action

pramodkumar
Tera Expert

Hi All,

I am using g_form.elements.length in workspace client script UI action. I am trying to bypass all mandatory fields and save data. It is working in regular form view, but not in workspace. Can we bypass all required fields in workspace and save form?

 

 

Thanks!

2 REPLIES 2

AnirudhKumar
Mega Sage

I'm sorry but I don't understand the purpose of that requirement. If the fields are mandatory, why do you want to override it only on workspace? If you want to allow the users to submit the form, then you might as well set the fields to mandatory false on all views.

Tanushree Maiti
Kilo Patron

Hi @pramodkumar 

 

g_form.element is deprecated (Refer: GlideForm (g_form) - Client ). 

While it works in the "Core UI" (standard platform), it will fail in Workspace because the underlying DOM structure is different and modern Workspace APIs enforce stricter isolation.

 

Instead of g_form.elements, use g_form.getEditableFields() to retrieve an array of field names. This method is compatible with Workspace.

 

Sample code:  <write code as per your requirement>

Refer: https://www.servicenow.com/community/developer-forum/workspace-client-script-ui-action/m-p/2516509/p...

 

function onClick(g_form) {
    var fields = g_form.getEditableFields();
    for (var i = 0; x < fields.length; i++) {
        g_form.setMandatory(fields[i], false);
    }
    g_form.submit();
}

  

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: