EPM GROOVY – Add Entries to Smartlists Dynamically (No, Not from hierarchies)

Smart List drop-downs are used to select predefined values in a data form. They are typically associated with a member. If the number of entries is expected to grow, a hierarchy-driven Smart List can be used. This will automatically update the list of entries as the number of members in the hierarchy increases. However, an alternate approach is to use a business rule to update the entry list. This will eliminate the need to deal with hierarchies.

In other words, Smart List drop-downs are used to select values from a predefined list. This list can be updated manually or automatically. If the list is expected to grow, it is better to use a business rule to update the list automatically, especially additional hierarchies required to be maintained.

How did we do this before Groovy APIs?

Previously, we could not update Smart List entries using Meta Data import because:

  1. We could not trigger the import Meta Data job from a business rule.
  2. The import Meta Data job only accepts CSV files as input, and we did not have APIs to create CSV files from a business rule.

However, now we can use Server-side EPM Automate and CSV Writer functions in Groovy Rules to:

  1. Dynamically create a CSV file containing the new Smart List entries.
  2. Import the new Smart List entries into the application.

This means that we can now update Smart List entries using a business rule, which gives us more flexibility and control over the process.

Use case

In this demo, I will show how to create a Smart List that is automatically updated based on the files that are available in the Inbox/Outbox directory.

  1. First, I will upload 5 data files to the Inbox/Outbox directory. These files will all start with the word “Budget”.
  2. Then, I will create a Smart List that contains 5 entries, each of which is the name of one of the Budget files using Groovy Business Rule.
  3. The user will be able to choose one of the files from the Smart List and load the data into the application using a Business Rule.
  4. Once the file is imported, the user may opt for an option to delete it.
  5. If the file is deleted, the Smart List will be updated to remove the entry for that file.
  6. This means that the Smart List will only show the files that have not yet been imported.

The goal of this is to make it easier for the user to keep track of the files that need to be imported. By removing the processed files from the Smart List, the user can focus on the pending files.

Let’s look at the script

Create a CSV file with Smartlist Entries

  1. Get the list of all the files in the inbox/outbox directory. This can be done using the getItemsLists() method in the listFiles EPM Automate process.
  2. Filter the file names to only include those that start with the word “Budget”. This can be done using the startsWith() method in the String class.
  3. Create a Smart List Entry file that contains the names of these files. This can be done using the write() method in the createFileWriter() function.

Special characters cannot be used in Smart List entry values. Therefore, before continuing, please review the documentation.

Groovy
createFileWriter('SmartList_Update.csv').withCloseable() { smartListEntry ->
	smartListEntry.write('SmartList Name,Operation,Label,Entry Name,Entry Label\n')
	smartListEntry.write('SL_Files,addsmartlist,SL_Files,,\n')
	files.each { file -> smartListEntry.write("SL_Files,addentry,,${file.toString().replace(".", "_")},$file\n") }    
}

In order to build the Smartlist entries, I only used the most basic columns.

Please update the Smart List entries using server-side EPM Automate after the file is created.

To call the data import, file deletion, and Smart List update, I wrote another Groovy  template.

Since the most of us are familiar with the EPM Automate commands, I won’t go over the Server-Side EPM Automate components.

Lets Execute the code

We are rebuilding the Smart List after each file is processed. We don’t need to alter the Meta Data because it isn’t connected to any members.

My Current Inbox/Outbox directory:

Lets run the template

This use case, in my opinion, is not really solid. I want to demonstrate how much easier it is now to create and update smart lists if you need to deal with dynamic list creation and don’t want to utilize hierarchies to accomplish the same.

I hope this information is helpful.