Need help hiding a Workspace button based on reference record and logged-in user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
i did, still not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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
};
}
}