Run a sub process for each record in a selected folder

Hi all,

I have a process where a user selects a contact folder from a list on a preconfigured page. A sub process then needs to run for each contact in the selected folder.

I've read the article for Programmatically Using Section Folder Filters in Processes or Server-Side Code in Creatio | Customer FX and I have borrowed a script task for creating the list of contacts.

var sectionName = "Contact";
var folderId = "2d3c0306-1e43-4ba7-943b-a3d261b66897"; //I will pass this in from the preconfigured page
 
// get folder SearchData
var folderSchema = UserConnection.EntitySchemaManager.GetInstanceByName(sectionName + "Folder");
var esq = new EntitySchemaQuery(folderSchema);
var dataCol = esq.AddColumn("SearchData").Name;
var folderData = esq.GetEntity(UserConnection, folderId).GetBytesValue(dataCol);
 
// convert filter data to esq filters
var serializedFilters = System.Text.Encoding.UTF8.GetString(folderData, 0, folderData.Length);
var dataSourceFilters = Terrasoft.Common.Json.Json.Deserialize<Terrasoft.Nui.ServiceModel.DataContract.Filters>(serializedFilters);
 
// MUST INCLUDE using Terrasoft.Nui.ServiceModel.Extensions;
var folderFilters = dataSourceFilters.BuildEsqFilter(UserConnection.EntitySchemaManager.GetInstanceByName(sectionName).UId, UserConnection);
 
// now can include folderFilters as filters in new esq
var contactEsq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "Contact");
contactEsq.AddColumn("Id");
contactEsq.Filters.Add(folderFilters); // using the filters from the folder
var contacts = contactEsq.GetEntityCollection(UserConnection);

I would like to either pass the results into a collection or run a sub process for each contact directly from the script task.

Any help would be much appreciated,

Like 0

Like

1 comments

An easy way to accomplish what you're after is to: 

  1. Create a collection parameter in the process
  2. Populate the contacts from the ESQ into the collection parameter (see link below)
  3. Then use normal subprocess for each contact in the collection

See here for how to add the results of the ESQ from the folder to a collection param: https://customerfx.com/article/working-with-collection-parameters-in-a-process-in-creatio/

Ryan

Show all comments