Showing posts with label subgrid. Show all posts
Showing posts with label subgrid. Show all posts

Monday, March 30, 2015

Hide SubGrid '+' / New Button button based on Parent status

Hide child  records sub grid + or Add New button

Some time we need to hide  '+' button or Add New button for child record grid..





You can do this by adding enable rule for + or Add New Button.

1. Open Child record customization in Ribbon workbench

2.  Select Entity so that we will able to modify command definition.

3. In Sub Gird, select + Add New {0} Button, right click and select Customize Command



4.  Add New Enable Rule


5. For Enable Rule.. Add steps, and select Custom JavaScript Rule

6. Set Custom rule properties as 
Default : true
Function Name: DisableSubGridNewButton
Invert Result : False
Library: JavaScript web resource where you added DisableSubGridNewButton function 
Parameters : None. 



JavaScript DisableSubGridNewButton Function 

-- When Form is ready only then hide +new or Add new Button for child records.
function DisableSubGridNewButton() {
    if (Xrm.Page.ui.getFormType() == 3) // Read Only
        return false;
    else
        return true;
}


-- based on Some values on Form

function DisableSubGridNewButton() {
    var IsMarried = Xrm.Page.getAttribute('new_status').getValue();

    if (IsMarried == 70000001) //un marriged
        return false// Hide button
    else
        return true//Show button
}


7. Add this enable rule to button Command



8. Save and Publish Customization.



Tuesday, February 17, 2015

Dynamically Filter form sub grid to show related records

Scenario: 

I have different Cars in system, and cars has different categories, when one car record is opened, I want to show all other cars of same category in sub grid.

Main thing is that there is not any relationship between cars.

Basically need to filter sub grid dynamically based on category of current record and show related records.



Resolution:

To achieve this there is not fully supported way, so I did using unsupported way..

1. Add Sub grid on form for car entity.

When adding sub grid, make sure initially show all records.
2. Add JavaScript web resource in Form library

3. Add following code in JavaScript Web resource




  

4.  Save form and publish. 

5. Now form subgrid is showing only related records based on category