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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Hide Reopen Opportunity button based on Teams

(1) ShareShare
ReportReport
Posted on by
 
Hi, 

Could someone help me figure out what I must be doing wrong?
In a Dev instance, I am trying to hide the 'Reopen Opportunity' Button on the closed opportunity record to restrict it to users who are members of owner team with the team id value of 2df71575-xxxxxxxxxx'
I 've associated the JS to the Opportunity form, and I am not getting no client side script errors.
 
 
function hideReopenOpportunityButtonOnClosedOpportunity(executionContext) {    var formContext = executionContext.getFormContext();    var opportunityStatus = formContext.getAttribute(/msdyn_forecastcategory/).getValue();    var ownerTeamId = '2df71575-2c18-ef11-9f89-6045bda21d2c'; // The specific owner team ID    //     if (opportunityStatus === 100000005) {        var currentUserId = Xrm.Utility.getGlobalContext().userSettings.userId.replace(/{/, //).replace(/}/, //);        // Fetch the teams the current user is a member of        fetchUserTeams(currentUserId).then(function(teams) {            var isMemberOfOwnerTeam = teams.some(function(team) {                return team.teamid.toLowerCase() === ownerTeamId.toLowerCase();            });            if (!isMemberOfOwnerTeam) {                // Hide the /Reopen Opportunity/ button                hideReopenOpportunityButton(formContext);            }        }).catch(function(error) {            console.log(error.message);        });    }}function fetchUserTeams(currentUserId) {    var query = //systemusers(/ + currentUserId + /)/teammembership_association/;    return Xrm.WebApi.retrieveMultipleRecords(/team/, query).then(function(result) {        return result.entities;    });}function hideReopenOpportunityButton(formContext) {    var reopenButton = formContext.ui.controls.get(/Reopen Opportunity/);    if (reopenButton) {        reopenButton.setVisible(false);    }}
 
Expected behaviour- Test user (not a member of User Team) should not see Reopen Opportunity button 
 
Actual behaviour - Test User is seeing the Reopen Button
//
 
Button command properties and solution layer on the command is not showing unmanged layer
 
//
 
 
//
 
However, button itself has the expected unmanged customization
 
Ribbon workbench set up as below
 
//
 
 
Ribbon diff xml
<?xml version=/1.0/ encoding=/utf-16/?><RibbonDiffXml xmlns:xsd=/http://www.w3.org/2001/XMLSchema/ xmlns:xsi=/http://www.w3.org/2001/XMLSchema-instance/>  <CustomActions>    <CustomAction Id=/vinu.Mscrm.Form.opportunity.ReopenOpp.CustomAction/ Location=/Mscrm.Form.opportunity.MainTab.Actions.Controls._children/ Sequence=/5/>      <CommandUIDefinition>        <Button Alt=/$LocLabels:Mscrm.Form.opportunity.ReopenOpp.Alt/ Command=/Mscrm.Form.opportunity.ReopenOpp/ Id=/Mscrm.Form.opportunity.ReopenOpp/ Image32by32=//_imgs/ribbon/ReopenOpportunity_32.png/ Image16by16=//_imgs/ribbon/ReopenOpportunity_16.png/ LabelText=/$LocLabels:Mscrm.Form.opportunity.ReopenOpp.LabelText/ Sequence=/5/ TemplateAlias=/o1/ ToolTipTitle=/$LocLabels:Mscrm.Form.opportunity.ReopenOpp.ToolTipTitle/ ToolTipDescription=/$LocLabels:Mscrm.Form.opportunity.ReopenOpp.ToolTipDescription/ ModernImage=/ReOpenOpportunity/ />      </CommandUIDefinition>    </CustomAction>  </CustomActions>  <Templates>    <RibbonTemplates Id=/Mscrm.Templates/ />  </Templates>  <CommandDefinitions>    <CommandDefinition Id=/vinu.opportunity.Command0.Command/>      <EnableRules>        <EnableRule Id=/vinu.opportunity.EnableRule0.EnableRule/ />      </EnableRules>      <DisplayRules />      <Actions>        <JavaScriptFunction FunctionName=/hideReopenOpportunityButtonOnClosedOpportunity/ Library=/$webresource:crc3e_hideReopenV2/ />      </Actions>    </CommandDefinition>  </CommandDefinitions>  <RuleDefinitions>    <TabDisplayRules />    <DisplayRules />    <EnableRules>      <EnableRule Id=/vinu.opportunity.EnableRule0.EnableRule/>        <CustomRule FunctionName=/hideReopenOpportunityButtonOnClosedOpportunity/ Library=/$webresource:crc3e_hideReopenV2/ Default=/false/ InvertResult=/false/ />      </EnableRule>    </EnableRules>  </RuleDefinitions>  <LocLabels>    <LocLabel Id=/Mscrm.Form.opportunity.ReopenOpp.LabelText/>      <Titles>        <Title description=/Reopen Opportunity/ languagecode=/1033/ />      </Titles>    </LocLabel>    <LocLabel Id=/Mscrm.Form.opportunity.ReopenOpp.ToolTipTitle/>      <Titles>        <Title description=/Reopen Opportunity/ languagecode=/1033/ />      </Titles>    </LocLabel>    <LocLabel Id=/Mscrm.Form.opportunity.ReopenOpp.ToolTipDescription/>      <Titles>        <Title description=/Reopen this opportunity to make it active and continue working on it./ languagecode=/1033/ />      </Titles>    </LocLabel>    <LocLabel Id=/Mscrm.Form.opportunity.ReopenOpp.Alt/>      <Titles>        <Title description=/Reopen Opportunity/ languagecode=/1033/ />      </Titles>    </LocLabel>  </LocLabels></RibbonDiffXml>
 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 103

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 83 Most Valuable Professional

#3
11manish Profile Picture

11manish 65 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans