List resources

List resources

The advanced, utilities workflow component, List resources can be used in order to generate a list of all resources in a specific directory. The list is generated as an XML file and is output into the payload of the current workflow.

 

Please notice, that the previous payload will be overwritten, but you can keep a copy of the original payload before running this component e.g. with the Payload to named property and then later restore the payload from the named property with the component, Named property to payload.

 

A related workflow component is: List filesystem directory.

 

The list resources workflow component has these parameters:

NG2WorkflowListResources0001

 

Resource type

Here you can select the resource type either from the drop down list or via an XPath expression. If you use an XPath expression, then you can find help in the Delete resource section concerning what to specify for each of the resource types.

 

Resource path

Here you can specify a relative path within the selected resource type. If you state /, then you refer to the root of the specific resource type.

 

Include sub-folders

Here you indicate if only the selected resource folder should be selected, or if you also want to include all the sub-folders within this folder.

 

The output XML file looks like this:

 

NG2WorkflowListResources0002

 

Here are a few examples of how the component, List resources can be used in InterFormNG2:

 

Example 1: An example of how this can be used for deleting old, temporary resources is included below.

Example 2: How to collect PDF files found in a resource folder and send an email with all the files as attachments.

Example 3: Addition to example 2: Only send the email if at least one resource file has been found.

Example 4: Extension to example 2: Send email to each customer with all waiting PDF files

 

 

 

 

Example 1: Delete old resource files

One example of what you can use the List resources function for is to automatically delete old resources. Below a workflow is listed, that does exactly that. It is a bit long, below it has been cut up into two parts:

 

 

Part 1:

NG2ListResources0002

 

Part 2:

NG2ListResources0003

 

Each of the 8 elements are shown and explained below:

 

1.Scheduled start

With the scheduled start we setup InterFormNG2 to run this workflow each day at 20:05:

 

NG2ListResources0004

 

2.Set one workflow variable

Here we set a variable, DeleteAfterDays, that indicates how the resources should be in order for them to be deleted. In this case we set this to 30 days. This variable will be used later in a condition.

 

NG2ListResources0005

 

3.List resources

Here we choose to list all resources in the other folder of the Library. All files including files in the sub-folders are included in the output XML file, which is stored in the payload for later use.

 

NG2ListResources0006

 

4.Set one workflow variable

This sets the predefined variable, interform.log.disable.JobLog to true, which means that from now on the job log will be disabled. This is done in order to reduce the job log entry as a lot of resources might be deleted.

 

NG2ListResources0007

 

5.Split XML

This splits up the XML file (that contains the list of resources) into smaller XML files - one per resource. From here the rest of the workflow is executed for each of these smaller XML files. Please notice, that the new, smaller XML files has a changed structure as they have the resource node as the root node.

 

NG2ListResources0008

 

6.Set one workflow variable

Here we set the variable, Age and the value is calculated as the number of days from the day, when the current resource was changed until the current timestamp. It uses the two XPath functions, days-from-duration (which returns the number of days based on a duration) and the xs:dateTime function (which formats the timestamp of when the resource was modified).

 

NG2ListResources0009

 

7.Choice..when

This condition determines if the current resource has the extension .xml (as we in this case only wants to delete old .xml files) and the same time the age of this resource (stored in the variable, Age in step 6) must be larger than the limit we set in the variable, DeleteAfterDays (specified in step 2).

 

NG2ListResources0010

 

8.Delete resource

Here we delete the current resource found in the XML split loop:

 

NG2ListResources0011

 

 

Example 2: How to collect PDF files found in a sub folder in resources and send an email with all the files as attachments.

The list resources workflow component can be used if you e.g. want to collect all waiting PDF files in a resource folder of the Library e.g. the other folder and add the PDF files as attachments to an email. This can especially be considered if InterFormNG2 is not allowed direct access to the file system. If access to the file system is allowed, then you can consider to store the PDF files as files in a normal folder an use the List filesystem directory component.

 

Below you can see an example of how this can be done with List resources:

 

NG2ListResources012

 

Starting from the left the details of each element is documented below:

 

The input for the workflow is here Scheduled start. In this setup it is setup to run at the end of each workday at 17:00 (5 pm). I have chosen in advance to create a sample XML file as it is created with the list resources function, load that in the document library and refer to that here to ensure, that XML references are correct.

 

NG2ListResources013

 

The first workflow element is the List resources component:

 

NG2ListResources014

 

With this setup all PDF files in the folder PDFs of the other library are listed in an XML file which is saved to the payload.

 

Next we have a choice and join element, which makes it possible to first create the many attachments, store them and then use them in the join branch. Here the choice has a simple dummy condition which is always true:

 

NG2ListResources015

 

This dummy condition is here 1=1, which of course is always true. Another similar condition could be the xpath function: true().

 

Inside the choice branch the first element is a Split XML component, which is setup like below:

 

NG2ListResources016

 

The split XML splits on the /resources/resource nodes, so it will create new XML files like below for each PDF file:

 

  <resource>

     <name>File_1001(1).pdf</name>

     <path>PDFs/File_1001(1).pdf</path>

     <modified>2024-05-29T10:25:38</modified>

  </resource>

 

With the option, collect attachment the workflow will keep all of attachments, that are created while splitting the XML file.

 

Inside the split xml the component, Resource to attachment is used in order to create an attachment matching the file found in the splitted XML:

 

NG2ListResources017

 

With the setup above the name of the attachment will be the same as the file name of the resource file. For the path to the resource we need to add the 'other' folder in front (|| is concatenate) to build the complete path to the resource - as the input file are here stored in the other Library.

 

After we have added the resource file as an attachment we can consider to delete the resource with the delete resource component like below:

 

NG2ListResources018

 

Again we use the same expression as in resource to attachment to delete the resource.

 

After all the splitting is done - and all the resource PDF files has been added as attachments the join branch of the choice and join component is executed. Inside the join branch we send the email with the attachments, that has been added while splitting. That is done with the component, Send an HTML email like below:

 

NG2ListResources019

 

There is only detail missing: You probably only want to send out the email if at least one file was found. Such a condition is added in the example below.

 

 

Example 3: Only send the email if at least one resource file has been found

This is an addition to example 2 above. This shows how you can ensure, that an email is only sent if at least one input PDF file has been found.

 

One way to do that is to add a condition (choice element) immediately after the List resources component like below:

 

NG2ListResources01

 

The Otherwise branch of the extra choice element has been deleted as that is not needed. The condition in the new choice can look like below:

 

NG2ListResources020

 

 

 

Example 4: Send email to each customer with all waiting PDF files

This section is an extension to the previous examples above. In this example we have multiple folders - one for each customer, and in each folder we might have multiple PDF files, that we want to attach to the email.

 

For this example we consider a structure in the others library like this:

 

NG2ListResources021

 

Where 001 and 002 are customer numbers and the PDF files for each of these customers are placed in each of these subfolders.

 

The new complete workflow is shown here:

 

Part 1:

NG2ListResources022

 

Part 2:

NG2ListResources023

 

Here each of the elements are covered and described from left to right:

 

The first two are the same as in example 2:

 

The input for the workflow is here Scheduled start. In this setup it is setup to run at the end of each workday at 17:00 (5 pm). I have chosen in advance to create a sample XML file as it is created with the list resources function, load that in the document library and refer to that here to ensure, that XML references are correct.

 

NG2ListResources013

 

The first workflow element is the List resources component:

 

NG2ListResources014

 

With this setup all PDF files in the folder PDFs of the other library are listed in an XML file which is saved to the payload.

 

The third workflow component is a transformation, which extracts the customer number from the path of each resource and adds a new node, CustomerNo where the value is the customer number (here also with a slash in front and back as a way to ensure, that the full customer number is found). This extra node is added as a way identify the different customers for which a PDF file has been found.

 

The transformation is referenced with the component, XSL transformation as below:

 

ListResources024

 

The transformation is setup as below:

 

ListResources025

 

This was quickly created by building a transformation based on the XML file created by List resources as both input and output and then adding the CustomerNo node as below:

 

NG2ListResources026

 

In this case the actual customer number is found in position 6 to 8 of the path node, but here the preceding and trailing slash (/) is also included. You might choose not to include them.

After this component the payload is changed as the CustomerNo node is added.

 

 

We intend to run a repeat loop, but first we need to define a count variable in order to keep track of the current index in the fourth component like below:

 

NG2ListResources026

 

 

Next we need to add a repeat to run through all the customer numbers for which at least one PDF file has been found. This is done with this setup:

 

NG2ListResources027

 

The distinct-values() function creates a list of all unique values found in the CustomerNo nodes. In this case this list consists of two elements: "/001/" and "/002/". With the count function we count the number of unique values which in this case is 2, so the repeat runs two iterations in this case. We need to enable the option 'Keep variable values and payload between repeats' to keep the value of the count variable and increment it for each iteration.

 

 

Inside the repeat we first update the variable, count to increment it with 1 like below and also extract the current Customer number into the variable, CustomerNo:

 

NG2ListResources028

 

 

Now we move into the choice and join which has the same dummy condition as above:

 

NG2ListResources029

 

 

As the first element in the conditioned branch we still have a split XML element, but this is now changed as it should only select the PDF files for the current customer number:

 

NG2ListResources030

 

We still need to keep/collect the attachments for the email later.

 

 

Now we use the component, Resource to attachment like before to add the current PDF file as an attachment for the email:

 

NG2ListResources031

(This is unchanged from the initial example)

 

Next we delete the PDF resource, that we just attached as we do not want to add it next time:

 

NG2ListResource032

 

(It is a good idea to only delete the resource after the email has successfully been created, but it is done here to keep the workflow as simple as possible).

 

 

In the join branch of the select and join we still have the Send an HTML email workflow component:

 

NG2ListResources033

 

Here the CustomerNo variable is just used as the subject name, but that could also be used as a key in translation files to identify the receiving email address. It could also be more advanced were we could extract information from the PDF file names to identify the range of document numbers in the attachments.

 

 

There is one final detail to cover and that is to ensure, that the accumulated attachments are forgotten when we have sent the email, as we move on to build an email for the next customer.

 

We can do that with a dummy split XML, which clears the attachments. We need to refer to a node, that exists in the XML file in the payload, but that is not a problem when we refer to the root node like below:

 

NG2ListResources034

 

Please notice, that the 'Collect attachments' is disabled, which ensures, that the attachments are dropped from the memory of the workflow.

    • Related Articles

    • List filesystem directory

      You can use InterFormNG2 to generate a list of all files in a specific directory (and even include files in sub-directories) and output the list as an XML file. This can be done with the advanced, utilities workflow component called: List filesystem ...
    • Versioning of resources

      One optional feature in InterFormNG2 is versioning of resources. The versioning features makes it possible to maintain a version history on resources in the library. Versioning of resources is a way to keep track of changes to resources and this can ...
    • Export selected resources and configurations

      It is possible in InterFormNG2 to export resources in multiple ways. This section covers the option to export only selected resources and/or configurations of a tenant. This option is linked with the import resources options, which is also shown on ...
    • Save in resources

      When using systems like IBM i or in the cloud, then sometimes the client needs an easy way to save an XML for later viewing while creating and testing workflows. The IBM i green screen or remote desktop connection to cloud servers etc. is not an ...
    • Import selected resources and configurations

      This import option is linked with the export resources option in the way that the import option enables you to import all or some of the resources included in an export. The export comes as a zip file and you should not unzip the file first, but ...