Client Script not working in Service Operations Workspace

JLeong
Mega Sage

Hello!

How do I make this code work in Service Operation Workspace? I am trying to remove the Deny / Accept link

g_form.setReadOnly('state', true);
g_form.setReadOnly('sysapproval', true);
g_form.setVisible('document_id', false);
if(g_form.getValue('u_request') == '') {
var link = document.getElementsByClassName('web');
for(var i = 0; i < link.length; i++) {
link[i].style.visibility = 'hidden';
}
 
JLeong_0-1769827497044.png

 

 
1 REPLY 1

Itallo Brandão
Tera Guru

Hi JLeong,

Technical Analysis: The code is failing because DOM Manipulation (using document, window, or $) is strictly restricted in the Service Operations Workspace (SOW).

Workspaces are built on the Now Experience UI Framework, which utilizes Shadow DOM.

  • In Classic UI, the HTML is open and accessible.

  • In Workspace, components are encapsulated. Your script (document.getElementsByClassName) searches the top-level document, but it cannot penetrate the "Shadow Boundary" of the component where those links reside. It returns empty/null because it literally cannot "see" inside the component.

The Solution: You cannot cherry-pick/hide specific HTML elements (like just the links) inside a field or formatter in Workspace. You must handle the entire field/formatter or use Standard UI Actions.

Approach 1: Hide the Container (If it is a Formatter) Those links typically belong to the Approval Summarizer or a generic Macro formatter. Instead of trying to hide the specific .web class elements, you should hide the field that contains them.

  1. Find the variable/field name of that section (e.g., approval_history, summary, or the variable editor name).

  2. Use standard API:

    JavaScript
     
    // Instead of DOM manipulation
    if(g_form.getValue('u_request') == '') {
        // Hide the entire formatter/field containing the links
        // You need to find the specific element name in the form layout
        g_form.setVisible('variable_summary', false); // Example name
    }

Approach 2: View Rules (Recommended) If you cannot hide it via script because it is a Formatter without a clean name:

  1. Create a specific View for SOW.

  2. In that View, simply remove the formatter/field that generates those text links.

  3. Rely on the standard Workspace Header Buttons (UI Actions) for Approve/Reject, which are controlled by standard UI Action Conditions/Visibility.

Summary: document.getElementsByClassName will never work reliably in SOW due to Shadow DOM encapsulation. You must move to hiding the whole field via g_form or managing visibility via Form Layouts/Views.

If this explanation clarifies the Workspace limitation, please mark it as Accepted Solution.

Best regards,
Brandão.