Enable Record as Active or Inactive record in PowerApps | CloudFronts

Enable Record as Active or Inactive record in PowerApps

Introduction:

In this blog, we will learn how to Enable multiple records as active or inactive record.

Use Case:

We have a requirement where there is a Grid of CDS Data Source, on clicking the Deactivate or Active Button on top of the Grid, it should Deactivate every record which is selected through the checkbox which is there on every record of the Grid.

Steps:

There is a Screen on which there a Editable grid of custom Entity Objective.

To Create an Editable Grid refer to the following link.

To add Lookup Fields in the Grid refer to the following link.

This is the grid with a checkbox.

 To Deactivate or Activate selected records, first create a Collection:

OnSelect property of the Deactivate Button:

Set DeactivateButton.OnSelect =  
ClearCollect(			
<VariableName>,						      
Filter(
<GalleryName>.AllItems,<CheckBoxName>.Value = true
 )
)
	
	For eg: DeactivateSelectedRecord.OnSelect= 
	ClearCollect(
	SelectedObjectivesInactive,
	Filter(
	BrowseGalleryObjectives.AllItems,
	CheckboxObjectivesGrid.Value = true
	)
	)

When we select the Deactivate Button, it will collect all the records where the Checkbox is selected.

To Deactivate the records from the CDS, set the OnSelect property of the Deactivate Button to the following formula:

OnSelect property of the Deactivate Button:

Set DeactivateButton.OnSelect =  
ForAll(
<CollectionVariable>,
Patch(
'Gallery Data Source',
LookUp
(
'Gallery Data Source',
Condition
),
{
statecode: <Name of Status Field>.Inactive,
statuscode: <Name of Status Reason Field>.Inactive
}
)
)
	For eg: DeactivateSelectedRecord.OnSelect = 
	ForAll(
	SelectedObjectivesInactive,
	    Patch(Objectives,
	     LookUp(
	     Objectives,
	         Objective in SelectedObjectivesInactive[@Objective] 
	        ),
	     {
	         Status: 'Status (Objectives)'.Inactive,
	'Status Reason': 'Status Reason (Objectives)'.Inactive 
	        }
	    )
	)

Combine the Whole formula in the OnSelect property of Deactivate Button :

For eg: DeactivateSelectedRecord.OnSelect = 

ClearCollect(
SelectedObjectivesInactive,
Filter(
BrowseGalleryObjectives.AllItems,
CheckboxObjectivesGrid.Value = true
)
);
ForAll(
SelectedObjectivesInactive,
    Patch(Objectives,
     LookUp(
     Objectives,
         Objective in SelectedObjectivesInactive[@Objective] 
        ),
     {
         Status: 'Status (Objectives)'.Inactive,
'Status Reason': 'Status Reason (Objectives)'.Inactive 
        }
    )
)

Note: For Activating the record just replace the Inactive to Active in the Patch Formula

Conclusion:

Hope above Blog helps you Activate, Deactivate multiple records of CDS from the Grid.


Share Story :

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close