Akash Rajput Technology over a cup of coffee

Part 31: Understand Data Broker Transforms

1 min read

Featured Video Play Icon

Let’s say we bring data using data broker and we would like to transform it before we display it on the page. Think of it as Transform maps we use before we store the data in the target table, we use transform to massage the data. For this tutorial, let’s just think we got list of catalog items and before we display it, we filter them by those which has images. Well, this cannot be done with just filters as they do not work as is with field type as image.

Create new transform

  • Goto Data resources
  • Click Add
  • From Data resources section, click + New
  • Click Transform
Image 2021-03-08 at 2.54.27 PM
  • Fill in the fields, as appropriate
    • Name – Filter catalog items without pictures
    • Description – This transform will tranform the data from EVAM Data broker for Catalog Item and filter them if they do not have pictures
    • Properties and Script as follows.
[
    {
        "name": "catalog_items",
        "label": "Catalog Items",
        "description": "List of Catalog items to filter",
        "readOnly": false,
        "fieldType": "object",
        "mandatory": true,
        "defaultValue": ""
    }
]
function transform(input) {

    input.catalog_items.items = input.catalog_items.items.map(function(item) {

        var sys_id = item.propValues.model.sys_id;
        var attachment = new GlideSysAttachment();
        var agr = attachment.getAttachments('ZZ_YYsc_cat_item', sys_id);

        while (agr.next()) {
            if (agr.file_name == 'picture')
                return item;
        }

    });
	
	return input.catalog_items;

}
  • Create Access control to access this data broker with admin
  • Change the sys_id to the sys_ux_data_broker_transform sys_id

Lets Map the input of the transform to the EVAM Output

At last, Map the output of the transform to the Data set input

Great!! we should see all the catalog items which pictures now on the catalog page.

Akash Rajput Technology over a cup of coffee

Leave a Reply

Your email address will not be published. Required fields are marked *

Never miss a story from me, get updates directly in your inbox.
Loading