How to reference a component in UI Builder from a script

ChristopherY765
Tera Contributor

So my end goal is to hide certain attachments from views if they've been marked as having PHI.

I have a new column in the sys_attachments table called phi_pii that's a bool and an ACL that controls whether or not a specific attachment is viewable based on the bool and roles. 

 

My issue is that I'm having difficulties with trying to set the bool as true when trying to upload the attachment. 

My current attempt at a solution is adding a Checkbox to the UI builder page "Attachment with SNC" labeled "PHI Attachment". I want it so that if the checkbox is ticked when a user uploads an attachment, the attachment is marked as PHI. I believe I would need to use a business rule that would set this column, however, I'm not sure how to reference the Checkbox component or how I would go about doing that.

 

sys attachment table with PHI field.pngSow sidebar attachment checkbox.pngSOW sidebar tab attachment SNC.png

2 REPLIES 2

DivyV
Tera Expert

Hey Christopher — this is a really sensible thing to be building, and the confusion makes total sense. The short version: the reason you're struggling to "reference the checkbox from a Business Rule" is that you're reaching across two layers that can't see each other.

 

A Business Rule runs server-side, on the sys_attachment insert. At that moment it has no idea what a UI Builder checkbox component on the page is showing — component state lives entirely in the client, in the browser. So there's no clean handle for the BR to grab. That's the wall you're hitting.

 

The pattern that actually works in UI Builder is event-driven and stays on the client side:

Step 1 — Capture the checkbox value into page state. Add a client state parameter on the page (something like markAsPhi, boolean). Wire the checkbox component's "value changed" event so it sets that state parameter. Now the page remembers whether PHI was ticked.

Step 2 — Listen for the upload. The Attachments component fires an event when a file is added — check its event list in the component's config panel (the exact event name varies by version, so I'd confirm it there rather than guess). Add an event handler/mapping for that event.

Step 3 — Update the record on upload. In that handler, if markAsPhi is true, update the just-added attachment's phi_pii to true. The cleanest way is to call a Data Broker / data resource (or a scripted server action) that does a GlideRecord on sys_attachment and sets the field — passing in the sys_id from the upload event payload and your state parameter as inputs.

 

So the flow is: checkbox → client state parameter → attachment-added event → server action that flips phi_pii. No Business Rule needed.

 

One thing worth a sanity check: make sure the upload event actually hands you the new attachment's sys_id in its payload — that's what your server action needs to target the right record. And I'd build and test this in a sub-prod instance first, especially since the ACL is gating real PHI visibility — you'll want to confirm the flag is set before anyone could view the file.

 

Happy to go deeper on wiring the event mapping or the server action if you get stuck — good luck with it!

ChristopherY765
Tera Contributor

Would love some deeper explanation on the event mapping and server action!

 

So far I believe I've gotten the event mapping correct.

 

I did step 1.

For step 2 I set it so when the "Attachment upload succeeded" event executes, it will run my custom Transform data resource conditionally, only if "markAsPhi" is true.

 

Step 3 is where I'm having issues now. I'm a bit confused as to how to setup the Transform Data Broker Server Script. I have it marked to "Mutate server data", and I created an ACL with the sysid of my new script for an execute for a ux_data_broker. I'm just not sure how to use the input correctly. I believe my script/properties aren't correct which is causing my event handler to be incorrect.

phi data broker server script.png