Conditional formatting in Service Portal

Daniel Voutt
Tera Contributor

Hi,

 

I have a client script that looks if someone is active or not.  If they are no longer active it will display the username in the field in red text.  This gives a nice easy visual to see which records need updating if/when a user leaves the company.  I also need the same feature on our service portal, however the script does NOT work in the service portal looking at the same data even though I have updated the UI Type to "all".  When you load the page in the SP it generates a JavaScript error, so obviosuly something isn't quite right.

 

I see the attached message at the top of the client script - is this why the SP isn't processing this script correctly?

 

"New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. To disable this feature for all new globally-scoped client-side scripts set the system property "glide.script.block.client.globals" to false."

 

Has anyone done this and can maybe shed some light on why it's not working in the SP - should I be using a different method?  Does it need to be a catalog script even though I'm just accessing a data entry form?

 

Any guidance would be greatly appreciated.

 

Thanks in advance - Dan

1 REPLY 1

Vishal Jaswal
Giga Sage

Hello @Daniel Voutt 

You cannot achieve the same in the portal the way you achieved it in native UI as portal is about pages and widgets (this is where you need to apply css) 

To achieve something like below:

vishal_jaswal_1-1741708263837.png

 

vishal_jaswal_2-1741708269208.png

vishal_jaswal_0-1741708240617.png

vishal_jaswal_4-1741708351516.png

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    // Use getReference to fetch user details
    g_form.getReference('reported_user', function(user) {
        if (user.active === 'false') { // Check if the user is inactive
            // Add a red field message
            g_form.showFieldMsg('reported_user', 'This user is inactive.', 'error');
        } else {
            // Clear previous message
            g_form.hideFieldMsg('reported_user');
        }
    });
}

 

Hope it helps!


Hope that helps!