Configure EVAM to only return producers and items available for the logged in user?

Aaron Dalton
Tera Expert

Hello! I'm working on a portal in UI Builder and have been trying to set up an EVAM to basically get a service catalog going. Right now it's only got record producers in it, but I was wondering if there's a way to have the EVAM respect the "Available for" user criteria when returning the cat items and producers?

I can't seem to get anywhere beyond the basic EVAM config documentation that's out there and I didn't see any specific catalog oriented component available in UIB. Has anyone set up a catalog in a UIB portal and run into this before?

1 ACCEPTED SOLUTION

Muralidharan BS
Mega Sage
Mega Sage

Hi Aaron, 

I haven't tried this but I believe this should work,

1. configure EVAM to fetch records "dynamic me".

2. create a transform and get input from EVAM to check the criteria, you can infuse this API in the script section of the transform to check the access. 

GlideappCatalogItem.get('catalog item sys_id').canView();

collect the items and return the transformed object. 

Thanks

Thanks

View solution in original post

5 REPLIES 5

This worked! I can't do a dynamic me on the EVAM definition since it's pulling from sc_cat_item_producer, but I was able to create a transform on the output that then returned the correct items based on whether the logged in user is allowed to view them. Here's what I did:

 

  1. New record on sys_ux_data_broker_transform
  2. While you're at it, make a new ACL with a type of ux_data_broker and an operation of execute -- set the name to the sys_id of your new transform created in step #1. Add whatever security you need onto it, but you can't use the transform without an ACL.
  3. Back on the transform - add a property to get the output from an EVAM definition as an input to the transform:
    1. [
        {
          "name": "evambroker",
          "label": "EVAM Broker",
          "fieldType": "json",
          "valueType": "object",
          "readOnly": false,
          "mandatory": true,
          "description": "Graphql Query Output - Data bind to @data.evam_broker.compositeDataViews"
        }
      ]
  4. In the script field, add the necessary loop so we can loop through the output of the items from the EVAM broker.
    1. function transform(input) {
      
          // Loop backwards through the EVAM Broker's output so we don't have to deal with indexes as we splice
          for (var i = input.evambroker.items.length - 1; i >= 0; i--) {
              // Grab the catalog item/record producer sys_id
              var catItemId = input.evambroker.items[i].propValues.model.sysId;
      
              // Check if the logged in user is allowed to view it based on its user criteria
              if (!GlideappCatalogItem.get(catItemId).canView()) {
                  // If they aren't allowed, remove it from the EVAM's output
                  input.evambroker.items.splice(i, 1);
              }
          }
      
          // Return the entire EVAM output, minus the items the logged in user isn't allowed to view
          return input;
      }
  5. Back in UI Builder, open the page you need the transform on, add it in the data section, and bind the transform's input to your EVAM broker's compositeDataViews (e.g. @data.evam_broker.compositeDataViews).
  6. Change your component that's consuming the data (repeater, data row, etc.) to use the output from the transform.
    1. Since the transform is returning exactly the same structure as the EVAM broker was originally outputting (just with less items in the array), you should be able to do the same exact data binding on the component, just using the name of the transform instead of the name of the EVAM broker.