Getting Multi-select Records from a Creatio Freedom UI List via Code

Creatio 8.1 and higher supports multi-selected records in lists. You can add an action for the list, which get’s added to the list’s bulk actions bar at the bottom. You can pretty easily get the selected records in your own request handler code.

The first step is to add your own button to the list’s bulk actions bar.

When you do this, you’ll be setting up the action request handler in code in the same way you do for buttons (see article here). In the handler, the key part is to get the selected records. In order to do that, you’ll need to know what the attribute is that the List stores the selections in. The List will have a “selectionState” property where you’ll see this. Here’s a sample from a list:

{
	"operation": "merge",
	"name": "DataTable",
	"values": {
		"selectionState": "$DataTable_SelectionState",
		// ...
}

In that sample above, you can see the selectionState is bound to the attribute named “DataTable_SelectionState” (the $ is not a part of the name, that is what indicates it is bound to an attribute named that). The list will use an attribute named “DataTable_SelectionState” to store the selections. The value of that attribute will be an object that has a property named “selected” which will be an array of Id’s for the selected records. In the request handler you set up for the bulk actions button, you’d use the following to get the array of selected Id values:

const selectedIds = (await request.$context.DataTable_SelectionState).selected;

Note, in the code above, we’re getting the value of the DataTable_SelectionState attribute (and awaiting the result), then getting the selected property of the object returned. Now you can do whatever is needed with each Id, such as execute a process or perform some other bulk action.

Want content like this delivered to your inbox? Sign up for our newsletter!
ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

5 Comments

  1. Hi Ryan,

    I’m trying to get the selected items from a grid detail, but it doesn’t work.
    It seems is not available the request.$context.xxx_SelectionState object.

    Reply
    • For a list that is not a section list (like a detail) the attribute name is not going to be “DataTable_SelectionState”. You’ll need to look at the DataGrid element in the page code to determine the name of that attribute.

  2. Hello Ryan!
    thank you for the quick reply.
    If a user selects all items using the top checkbox the (await request.$context.DataTable_SelectionState).selected is undefined.
    In this case the (await request.$context.DataTable_SelectionState) returns { Type: “All” … }

    Reply
    • Sorry returns { type:”all” …

    • This is true. When all are selected there is no selected property but instead an “unselected” property, however, I don’t think you can get an array of the selections (even the Items property only shows the first page of records). I believe i’ve seen that this is a current bug with a fix coming in next version?
      I believe some of the out of the box bulk actions work against the list’s datasource rather than the selected items.

Submit a Comment

Your email address will not be published. Required fields are marked *