Auto-refreshing Views or Grid in D365 CRM | CloudFronts

Auto-refreshing Views or Grid in D365 CRM

We all know that Views show records based on filter criteria that is applied to the Views.

But, what if there is a custom button that will change the records status and according to the Views filter criteria it should not be present in the View. The View should have been Auto-Refreshed. We can achieve this by JavaScript. 

Use Case:

We had a requirement where we wanted to Auto-Refresh the View as soon as the status of record is changed. We have a custom button that will change the status of the selected records but when the Status changes, it  doesn’t auto refreshes the View. We had to manually reload the page or click on refresh button on the View. 

Steps:

1. When the status of the Record changes, you have the id of record then there’s a fully supported way which we can use to Auto-Refresh the View:

var updatedRecord = {};
updatedRecord.entityType = selectedItem.TypeName;     //selectedItem: On click of the custom button, we passed "SelectedControlSelecteItemReferences" as CrmParameter which grabs the information of all selected record from the view.
updatedRecord.id = selectedItem.Id;       
Xrm.Utility.refreshParentGrid(updatedRecord);

“refreshParentGrid=Refreshes the parent grid that contains the specified record.”

2. In our case, We had the custom button which changes the status of the record. This is the code:

	if (status == 100000001 || status == 100000002) {
	    var data = {
	        "new_status": "100000002"
	    }
	    Xrm.WebApi.updateRecord(selectedItem.TypeName, selectedItem.Id, data).then(
	
	        function success(result) {
	            var lookupOptions = {};
	            lookupOptions.entityType = selectedItem.TypeName;
	            lookupOptions.id = selectedItem.Id;
	            Xrm.Utility.refreshParentGrid(lookupOptions);
	            Xrm.Utility.closeProgressIndicator();
	
	            //alert("Task updated");
	        },
	        function(error) {
	            Xrm.Utility.closeProgressIndicator();
	            console.log(error.message);
	        });
	}

Suppose the custom button is called as “Submit”. On clicking the button it should change the Status and also the records should not be visible in the view as the filter criteria is Status= “In Progress and Rejected”

1. The filter of the View.

2. On clicking the Submit Button, the selected record should not be visible.

3. The View Auto-Refreshed and the selected records are not visible in this View.

Note: This can be used in Sub-grids of the forms also.

Conclusion:

I hope this blog helps you to Auto-Refresh the View.


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