Skip to main content

Notifications

Announcements

No record found.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans