Attached document

Value resolver – Abstract

Purpose: Returns the contents of all Documents assigned to an entity in the input value and belonging to the optionally specified Document type.

images/download/attachments/119253859/image2023-1-25_10-5-10-version-1-modificationdate-1674637510130-api-v2.png

The Attached document value resolver expects an entity as input value and returns an array listing the 'Contents' from the documentContent field of all Documents that meet all of the following criteria:

  1. Read access exists for the document in the applicable context.

  2. The 'Referenced object' (referencedEntity) field of the document refers to the type of entity in the input value.

  3. The 'Referenced object ID' (referencedEntityId) field of the document refers to the ID (id) of the entity in the input value.

  4. The 'Reference status' (referenceStatus) field of the document refers to the 'Referenced' (REFERENCED) status.

NOTE◄ Each time a document is saved, the processes described in Assigning documents are started again to assign the document. If the assignment fails for a document that has already been successfully assigned, e.g. because another Document reference type is now selected that does not return an entity as a match, then the reference status after saving the document is 'Unresolved' (UNRESOLVED). This means that the document is not considered 'attached' from the point of view of the entity for which criteria 2 and 3 would still be fulfilled.

Special case:

  • If there is no entity as input value, the value resolver returns 'No value' ($null).

  • If the input value is an entity, but no Documents are found that meet the above criteria, an empty array is returned.

  • If the input value is an entity and exactly one document meets the above criteria, its content is returned as the only entry in an array.

NOTE◄ The value resolver is not used to access Documents as entities, but only returns their content. Access to the data of the document entities for 'Attached documents', on the other hand, would be provided, for example, by a Search (Event action) for the 'Document' (en.lobster.scm.doc.Document) entity type, which must map the above criteria (2, 3 and 4) with reference to the input value.

►CAUTION◄ The return value is an array and NOT a list ...


The fact that the return value is an array and not a real 'List' (List) may occasionally cause restrictions or require precautions. The following list does not claim to be complete:

  • An array does not pass a Check type for the 'List' (List) type. The combination of the 'Is collection of" option in connection with the 'Content' type in the Check type does not solve this problem.

  • Access to existing entries in the array via the List item value resolver is possible (in contrast to previous versions of Lobster Data Platform / Orchestration).

    • However, no entries can be added to the array.

  • With the Input object (type safe) value resolver, the array can be formally converted into a list which then also withstands type checking.

    • However, no entries can be added to this list either.

Configuration

The input value is expected to be an entity of any type, since Documents can only be assigned to entities, i.e. 'Attached' to them.

The optional of type parameter can be used to limit the selection of Documents to exactly one specific Document type by static single selection.

Without a selection for the of type parameter, the value resolver returns the contents of all assigned documents (criteria see above) regardless of their Document type.

The selection is supported by a search function which, as shown in the image, takes into account not only the localization but also the internal name for the Document type.

If Dynamic enum filters are applicable to the Document type in the context of the configuration, they restrict the selection. However, Dynamic enum filters do not change the runtime behaviour of a configuration.

images/download/attachments/119253859/image2023-1-25_10-6-13-version-1-modificationdate-1674637573160-api-v2.png

Example

Simple use case: 'Resume' file(s) attached to the user

An association criterion (see Association criteria) is considered passed if the input value in the data context is a Users for whose account at least one 'Attached' document of the Document type 'Curriculum Vitae' (CV) is found.

Configuration:

The association criteria combines two rules in an AND Junction:

  • In the input, a Check type ensures that Users are present in the context.

  • If this is the case, an Entity property rule should use the negated Is empty compare type to determine whether (at least) one resume document is found for the Users in the input value:

    • The Attached document value resolver searches for documents of type 'Curriculum Vitae' type and, if successful, returns a list of 'Content' objects with the documentContent of the found Documents.

    • The concatenated Store value as variable value resolver stores the result list in the docCV variable. If the present association criteria is used e.g. in the context of an event handling as a Sub criterion rule, the attached 'Curriculum Vitae'' contents can be accessed via this variable.

images/download/attachments/119253859/image2023-1-25_10-8-40-version-1-modificationdate-1674637720430-api-v2.png

Runtime example: Value of the variable docCV if exactly one attached PDF document with the Document type 'Curriculum Vitae' (CV) was found for the user.:

<value xsi:type="array">
<item mediaType="application/pdf" name="cv-2801.pdf" xsi:type="core:Content">
<body>JVBERi0xLjUNCiW1tbW1DQoxID[...]</body>
</item>
</value>
  • The return value is an array object with an item of the 'Content' (Content) type.

  • The 'Content' object represented by the item element contains the base64 file content in the body element as well as the 'Media type' (mediaType) and 'Name' (name) as XML attributes.

More complex use case: Compile file attachments for a shipment

A Custom action event event triggers a notification by e-mail in the context of a workflow for a business object of the 'shipment' (Shipments) type.

The following files should be attached to generated E-mails:

The body of the mail should list the names of the attached documents. Therefore, all attachments are collected in an attachments list variable before the E-Mail event action is executed.

Configuration:

The screenshot on the right shows an excerpt from an event handler that controls the assignment to the attachments list variable via Set value event action:

On the right side of the assignment, the list of all relevant attachments is compiled by a value resolution chain:

  • The first entry in the Create list value resolver retrieves the contents of all Documents assigned to the shipment in the input value:

    • Here the Attached document value resolver is used without any selection for of type parameter, so that it provides the contents of all Documents as an array without regard to the Document type.

    • The concatenated Input object (type safe) value resolver converts the array into a list (List), which is necessary here because the Join collections option in the concatenated Collect values value resolver below does not automatically treat the array like a real list.
      NOTE◄ The Type 'Content' is explicitly assigned here only for the purpose of transparency in the configuration. A type conversion on the level of entries is neither necessary here nor would it be represented in this form (see Input object (type safe)).

  • The second entry in the Create list value resolver obtains the 'General Terms and Conditions' via the File reference value resolver using a statically defined relative path (./upload/AGB.pdf). This value resolver returns the 'Content' (Content) of the file stored there at runtime.

  • The concatenated Collect values value resolver below converts the 'nested' list structure created above into a flat list of 'Content' objects by setting the Join collections option and configuring the Value to collect via Object property value resolver without selecting a field.
    IMPORTANT◄ It would be counterproductive here to use an Input object (type safe) value resolver with the 'Content' (Content) type for the Value to collect instead of the Object property value resolver, since the Join collections is only applied after the Value to collect.

images/download/attachments/119253859/image2023-1-25_10-10-25-version-1-modificationdate-1674637825566-api-v2.png