Hi Community!

 

How can I bind the selected row of a list to a property in the ViewModel, or even how can I execute custom code (custom handler) when the row is changed?

Thanks advance!
Ignacio

Like 0

Like

1 comments
Best reply

Hi,

 

Here is a simple code with an example of how to retrieve selected records:

{
            request: "crt.HandleViewModelAttributeChangeRequest",
            handler: async (request, next) =>  {
              if (request.attributeName === 'GridDetail_9ib3s20_SelectionState') {
                const gridDetailSelectionState = await request.$context.GridDetail_9ib3s20_SelectionState;
                if (gridDetailSelectionState) {
                   let selectedRows = await request.$context.GridDetail_9ib3s20_SelectedRows || []
;
                  console.log(selectedRows);
                }
              }
              return next?.handle(request);
            }
          }

It's triggered when the record is selected in the list and retrieves all selected rows in the list. If you need to retrive currently selected record you may add the following line

 

const lastRowSelected = request.$context.GridDetail_9ib3s20_ActiveRow;

 

Also don't forget to change GridDetail_9ib3s20 to your list.

Hi,

 

Here is a simple code with an example of how to retrieve selected records:

{
            request: "crt.HandleViewModelAttributeChangeRequest",
            handler: async (request, next) =>  {
              if (request.attributeName === 'GridDetail_9ib3s20_SelectionState') {
                const gridDetailSelectionState = await request.$context.GridDetail_9ib3s20_SelectionState;
                if (gridDetailSelectionState) {
                   let selectedRows = await request.$context.GridDetail_9ib3s20_SelectedRows || []
;
                  console.log(selectedRows);
                }
              }
              return next?.handle(request);
            }
          }

It's triggered when the record is selected in the list and retrieves all selected rows in the list. If you need to retrive currently selected record you may add the following line

 

const lastRowSelected = request.$context.GridDetail_9ib3s20_ActiveRow;

 

Also don't forget to change GridDetail_9ib3s20 to your list.

Show all comments

Hi,

 

I have a Freedom UI list where I can take a few actions after the user has selected one or more rows. The actions run as expected, but the records are kept selected after the actions run and the user has to manually clear the selection. What do I need to add to the custom code to clear the selection? 

Thanks,
Jose 

File attachments
Like 1

Like

7 comments
Best reply

Jose Hernandez,

 

You need to try

 

request.$context.GridDetail_tviz7gf_SelectionState = null
 

null is needed to remove the selection, but also change GridDetail_tviz7gf to your list attribute.

Hello,

Could you describe exactly what your custom logic performs for better understanding?

Malika,

 

It depends on the action. The Unlock one just clears the locked by field for the selected cases. The print generates letters and sends them to our print vendor for each case selected. Finally, the Assign one opens a window where the user can select the person to assign the cases to. Each one is calling the code below with the proper parameters.

I just need to know what I need to add to that code to clear the selection after the code that runs the business process.

 

Thanks,

Jose

        processSelectedRows: async function(request, processName, message, next) {
            var selectedRecords = await this.getSelectedRows(request.$context);
            var count = selectedRecords.count;
            var date = new Date();
            var hours = date.getHours();
            var minutes = date.getMinutes();
            var ampm = hours >= 12 ? 'PM' : 'AM';
            hours = hours > 12 ? hours - 12 : hours;
            var timeString = hours.toString().padStart(2, '0') + ':' + minutes.toString().padStart(2, '0') + " " + ampm;
            message = message + " on " + timeString + " for " +  count + " selected records.";
            request.$context.executeRequest({
                type: "crt.NotificationRequest",
                message:message
            });
            const handlerChain = sdk.HandlerChainService.instance;
            result = await handlerChain.process({
                type: 'crt.RunBusinessProcessRequest',
                processName: processName,
                processRunType: "RegardlessOfThePage",
                processParameters: {
                    "SelectedRecords": selectedRecords.selected
                },
                $context: request.$context
            });
            if (!result.success)  {
                var errorMsg = Ext.String.format(resources.localizableStrings.UnableToProcessSelectedRows, processName, result.errorInfo?.message);
                request.$context.executeRequest({
                    type: "crt.NotificationRequest",
                    message: errorMsg
                });                        
            }
            /* Call the next handler if it exists and return its result. */
            return next?.handle(request);
        }

I've not tried clearing the selections, but it might work to do this after you execute the process: 

request.$context.DataTable_SelectionState.selected = [];

Or it could be that you'll set SelectionState to null or {}?

Ryan

Ryan Farley,

Thanks Ryan. I tried that (and other variations like setting the type to 'clear') and the model gets cleared, but the GUI is not refreshed. In other worlds on the page the records are still showing as selected even though the model now has cleared the selection.

Jose Hernandez,

 

You need to try

 

request.$context.GridDetail_tviz7gf_SelectionState = null
 

null is needed to remove the selection, but also change GridDetail_tviz7gf to your list attribute.

Thanks Oleg. That worked. In my case I used  request.$context.DataTable_SelectionState = null; 

Viktoriia,

 

Hello,

 

It's 

 

request.$context.DataTable_SelectedRows
 

DataTable should be replaced with your list attribute name.

Show all comments

Hi,

I need to show selection checkbox for each record onload of Customers list view (screenshot). Currently checkboxes are showing only after clicking on Actions > Select multiple records

Any help will be highly appreciable.

 

Regards

Like 0

Like

2 comments

Hi Muhammad,



You should call method setMultiSelect in the section on the init function:



 

define("ContactSectionV2", ["css!UsrContactSectionV2CSS"], function() {
	return {
		entitySchemaName: "Contact",
		attributes: {},
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
		methods: {
			init: function() {
				this.setMultiSelect();
				this.callParent(arguments);
			}
		}
	};
});

 

Dmytro Smishchenko,

Thank you for suggestion, I checked its working but there is a issue.

Issue: when I click on record the form is appeared, then I clicked on "Close" button and return to listview then checkboxes are not showing.

Show all comments