Load Attachments to Display Object

Create and configure a list object to load the attachments. Add the list object to the Display business object and also add a datasource for the attachments.

Required Editions

Available in: Lightning Experience

Available in: Enterprise and Unlimited Editions where Consumer Goods Cloud is enabled

User Permissions Needed
To add and configure list object

Developer, Customizer

  1. To create a list object for attachments, in Visual Studio Code based Modeler, runsf mdl add and enter these details
     ? Select the resource you want to add. listobject
     ? Specify a name for the listobject: DisplayAttachment
     ? Select the module to which listobject 'DisplayAttachment' should be added. MyDisplay
  2. In DsLoMyDisplayAttachment_sf.datasource.xml, configure the datasource details as shown in this code snippet.
    <DataSource name="DsLoMyDisplayAttachment" backendSystem="sf" businessObjectClass="LoMyDisplayAttachment" external="false" editableEntity="SF_File" schemaVersion="2.0" readOnly="true">
       <Attributes>
          <Attribute name="attachmentBlobPKey" table="SF_File" column="Id" />
          <Attribute name="pKey" table="SF_FileLink" column="Id" />
          <Attribute name="mediaPath" table="SF_File" column="VersionData" />
          <Attribute name="description" table="SF_File" column="Description" />
          <DerivedAttribute name="type" value="replace(SF_File.PathOnClient, rtrim(SF_File.PathOnClient, replace(SF_File.PathOnClient, '.', '')), '')" />
          <DerivedAttribute name="fileType" value="replace(PathOnClient, rtrim(PathOnClient, replace(PathOnClient, '.', '')), '')" />
          <Attribute name="fileName" table="SF_File" column="PathOnClient" />
       </Attributes>
       <Entities>
          <Entity name="SF_File" alias="" idAttribute="Id" />
          <Entity name="SF_FileLink" alias="">
             <Join Type="inner">
                <SimpleJoin>
                   <Condition leftSideValue="SF_FileLink.FileId" comparator="eq" rightSideType="Attribute" rightSideValue="SF_File.Id" />
                </SimpleJoin>
             </Join>
          </Entity>
       </Entities>
       <QueryCondition><![CDATA[
          SF_FileLink.ParentId = #display#]]>
       </QueryCondition>
       <OrderCriteria>
          <OrderCriterion entity="SF_File" attribute="Relative_Position__c &lt;&gt; 0" direction="DESC" />
          <OrderCriterion entity="SF_File" attribute="Relative_Position__c" direction="ASC" />
       </OrderCriteria>
       <Parameters>
          <Parameter name="display" type="TEXT" />
       </Parameters>
    </DataSource>
  3. To configure the list object, in LiMyDisplayAttachment.listitem.xml, add these simple properties:

    The simple properties in this code snippet map specific attributes from the data source to properties in the application, including file keys, media paths, descriptions, types, and file names. Each property is linked to a corresponding data source property for accurate data retrieval.

    <SimpleProperty name="pKey" type="DomPKey" dataSourceProperty="pKey" />
    <SimpleProperty name="attachmentBlobPKey" type="DomPKey" dataSourceProperty="attachmentBlobPKey" />
    <SimpleProperty name="mediaPath" type="DomBlob" dataSourceProperty="mediaPath" blobTable="PrmAttachmentBlob" blobPKeyField="attachmentBlobPKey" />
    <SimpleProperty name="description" type="DomText" dataSourceProperty="description" />
    <SimpleProperty name="type" type="DomFileType" dataSourceProperty="type" />
    <SimpleProperty name="fileName" type="DomFileName" dataSourceProperty="fileName" />
  4. To add the list object to the BoDisplays business object, in BoMyDisplay.businessobject.xml, configure the list object under the ListObject node.

    The ListObjects section defines the loAttachment list object that uses the LoMyDisplayAttachment class and maps the pKey from the data source to the display list property. This ensures that the attachments correctly appear in the list.

    <ListObjects>
    	<ListObject name="loAttachment" objectClass="LoMyDisplayAttachment" dataSourceProperty="pKey" listProperty="display" />
    </ListObjects>
  5. Save all the contracts.