web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Hide SubGrid New Button button based on Parent status

(0) ShareShare
ReportReport
Posted on by 249

i try to hide the + button from Subgrid invoice detail in the entity invoice when statuscode is equal to 181510000 but it not worked any help!! 

 0412.2020_2D00_06_2D00_11-23_5F00_49_5F00_52_2D00_Ribbon-Workbench-2016.png

i do following:

1)create Javascript:

function hideSub(executionContext)
{
	var formContext = executionContext.getFormContext();
	if(formContext.getAttribute("statecode").getValue() == 181510000)
		return true;
	else 
		return false;
}

2) i add Enable rule

1768.2020_2D00_06_2D00_11-23_5F00_35_5F00_41_2D00_Microsoft-Word_2D00_Dokument-_2800_neu_2900_-_2D00_-Word.png

 

3) i add the rule to the command

 3660.pastedimage1591913601491v4.png

I have the same question (0)
  • Suggested answer
    MikeC282 Profile Picture
    2,175 on at

    Hey bud,

    Ribbon buttons don't get formContext the same way as on the form itself. You get the formContext from the primaryControl you pass as a parameter not the executionContext. See this great article on how to get the formContext from ribbon buttons. https://www.magnetismsolutions.com/blog/alfwynjordan/2019/10/02/getting-dynamics-365-formcontext-from-ribbon-workbench

    Try:

    function hideSub(primaryControl)
    {
    	var formContext = primaryControl.getFormContext();
    	if(formContext.getAttribute("statecode").getValue() == 181510000)
    		return true;
    	else 
    		return false;
    }

    Also try setting inverse result as false.

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Use below code to fix your issue.

    function hideSub(primaryControl)
    {
    	var formContext = primaryControl;
    	if(formContext.getAttribute("statecode").getValue() == 181510000)
    		return true;
    	else 
    		return false;
    }

    You will have to pass primarycontrol from ribbon. see below image.

    0434.CQ6.PNG

    OOB statecode value which you have mentioned in your code which is 181510000. you added new options?

    Why I ask this because OOB statecode optionset doesnot have this value

    .

    Invoice 0 Active 1 New
    2 Partially Shipped
    4 Billed
    5 Booked (applies to services)
    6 Installed (applies to services)
    1 Closed (deprecated) 3 Canceled (deprecated)
    7 Paid in Full (deprecated
    2 Paid 100001 Complete
    100002 Parial
    3 Canceled 100003 Canceled

    If found helpful, Please mark my answer verified.

  • Hedi bn Profile Picture
    249 on at

    hi,

    the statecode value yes i added, i have tested with your code but it still not working do you have another idea.

    thank u

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Strange!

    It seems to be working on my trial account.

    I myself validate this and posted blog as well.

    xrmdynamicscrm.wordpress.com/.../

    can you please share your code and screenshot of configuration you did on ribbon workbench.

    If found helpful, Please mark my answer verified.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans