Need help hiding a Workspace button based on reference record and logged-in user

dd31
Tera Contributor


Hi All,

I have created a button on Workspace using the Button component. I want to hide it based on two conditions:

The current record where the button appears has a reference in a specific table

The Assigned to field of current record should match the logged-in user.

Here’s what I did so far:

Created a Data Source (Transform ) to check these conditions.

Called that data broker from the Hide component visibility property of the button.

However, it’s not working as expected — the button isn’t hiding even when the conditions should match.

Could someone help me figure out what I might be doing wrong?

PFB SS for reference:

dd31_0-1755147821253.png

dd31_1-1755147905634.png

 

 

6 REPLIES 6

Shruti
Mega Sage
Mega Sage

Hi,

Did you create an ACL for new data resource?

If not, create an ACL

Type - ux_data_broker

Operation - execute

Name - sys_id of data resource

Assign relevant role 

 

Reference - https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_uibuilder_xanadu_ui...

 

dd31
Tera Contributor

i did, still not working

Ankur Bawiskar
Tera Patron
Tera Patron

@dd31 

I am not that much familiar with this but did you add gs.info() and debug?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yes

function transform(input) {
    try {
        var userSysId = gs.getUserID();
        gs.info("Transform Debug: Input assignedtosysid=" + input.assignedtosysid +
            ", recordsysid=" + input.recordsysid + ", userSysId=" + userSysId);

        var grci = new GlideRecord("x_g1001_competitiv_competitive_intelligence_table");
        grci.get(input.recordsysid);
        var vassignedsysid = grci.getValue("assigned_to");

        if (vassignedsysid == userSysId) {
            var grteam = new GlideRecord('sn_tcm_collab_hook_ms_teams_chat');
           // grteam.addQuery('source', input.recordsysid);
            grteam.query();
            if (grteam.next()) {
                gs.info("Transform Debug: Matching record found → show button");
                return false;
            }
        }
        gs.info("Transform Debug: No match → hide button");
        return true;
    } catch (ex) {
        return {
            error: true
        };
    }
}