Hi,
We have a business requirement to make dynamics 365 editable grid read only, we need to restrict user not to edit any more records after a field value is changed on a form, any suggestions ?
Thanks,
Shaik
*This post is locked for comments
Hello Aric, I have a requirement to Validate an editable grid, but I cant use the set notification method.
function validatePhoneNumber() { var addressSubgrid= Xrm.Page.getControl("AddressDetails").getGrid(); var selectedRows = addressSubgrid.getSelectedRows(); var phonenumber = selectedRows.get(0).getData().getEntity().getAttributes().get("new_phonenumber").getValue(); //var control = selectedRows.get(0).getControl("new_phonenumber"); console.log (phonenumber); // correct control.setNotification('Wrong Phone', 'ValidationAlert'); //wrong }
Using the Alert Dialog alone wont validate.
I am not using the execution context method here.
Hi Shaik,
You might can have a look on below blog:
https://crmbusiness.wordpress.com/2015/06/12/crm-2013-disabling-a-subgrid/#comment-25533
Thanks,
Anuj Govil
Hi Guys,
Code is Ok, apart from syntax error :) just to be precise.
function EditableGridReadOnly(context){
var entityObject = context.getFormContext().data.entity;
entityObject.attributes.forEach(function (attribute, i) {
var ctrl = attribute.controls.get(0);
ctrl.setDisabled(true);
}
)}
On the same, where do you get grid name?
I hope following code helps, but you have to select every record to make it non editable.
var editableGridLoadRetryCount = 0; function CRMEditableGrid_DisableFields(gridName) { var editableGridControl = Xrm.Page.getControl(gridName); // addOnRecordSelect doesn't work until the grid has propertly loaded. if (editableGridControl.getGrid().getTotalRecordCount() == 0 && editableGridLoadRetryCount <= 3) { editableGridLoadRetryCount = editableGridLoadRetryCount + 1; setTimeout("CRMEditableGrid_DisableFields(\"" + gridName + "\")", 500); return; } // Make fields read-only in Grid. editableGridControl.getGrid().addOnRecordSelect(function (executionContext) { var entityObject = executionContext.getFormContext().data.entity; entityObject.attributes.forEach(function (attribute, i) { if (attribute.getName() == "emailaddress1") { var emailControl = attribute.controls.get(0); emailControl.setDisabled(true); break; } }); } ); }
Thanks!!!
What happens when you click on a row in the grid. Does it show locks next to each field, or are they editable?
The code above does not make the subgrid read only just disabled the columns in each row.
When you attached the code to the RecordSelect event, did you check the Pass Execution Context checkbox?
Aric, I tried implementing the code, I couldn't achieve disabling the columns/cells in the subgrid. Though I have triggered the script on record select.
You need to get the context of the subgrid. Once you get the context, you can run the following code:
function setGridReadOnly(context) {
var entityObject = context.getFormContext().data.entity;
entityObject.attributes.forEach(function (attribute, i) {
var ctrl = attribute.controls.get(0);
ctrl.setDisabled(true);
}
});
}
The code does not disable the subgrid, but disables all the columns/cells in the subgrid
hi,
i too have same requirement please guide to achieve this
Hi,
Please replace the code as shown below.
function DisableSubgrid(){ // Get field value var value = Xrm.Page.getAttribute("AttributeName").getValue(); // Get subgrid control var subGridCtrl = Xrm.Page.getControl("SubgridName"); //Check the field value if(value == 'value') { // Disable the subgrid control subGridCtrl.setDisabled(true); } }
Hi Nithya - Thanks for your reply. we tried above code, its not working for Microsoft Dynamics CRM 365 editable subgrid, any other suggestions you have ?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156