Today I was going through Dynamics Community Forum and one of the question which was asked is to hide subgrid button based on parent entity field value.
As we all know, we can not directly use executioncontext in ribbon button. We have to use PrimaryControl to get form context from ribbon. We will have to pass PrimaryControl from ribbon workbench as a parameter.
I decided to implement this in my trial instance. So I want to hide Add Product on Invoice subgrid Invoice Line Items when “Status Reason” field value is not ‘New’.
See below screen on how to pass PrimaryControl from ribbon workbench.
Step 1:
Create new solution and add invoice line entity into it. Open ribbon workbench and choose the solution you created.
Step 2:
Navigate to Subgrid ribbon and select Add Product->right click and select customize command
Step 3:
Add new enable rule as custom rule to call below javascript code and pass primary control as a first parameter. Provide function name and choose web resource file.
function hideSub(primaryControl)
{
var formContext = primaryControl;
return (formContext.getAttribute(“statuscode”).getValue() === 1);
}
Step 4:
Publish your changes and navigate to Incoive form. Change Status reason from New to Partially Shipped and you will see Add Prouct button is not visible now.
Hope this helps!
Isn’t it easier to use
return (formContext.getAttribute(“statuscode”).getValue() === 1);
instead of
if(formContext.getAttribute(“statuscode”).getValue() == 1)
return true;
else
return false;
?
LikeLiked by 1 person
Hello Andrew,
Thank you for your feedback!
Updated based on your suggestion.
LikeLike
Hi Sir
I need a help regarding dynamics 365.
LikeLike
You are loading the invoice entity into ribbon workbench?
In step 2, how can you find the Product subgrid?
Related entity subgrids do not appear for me.
LikeLike