Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Need help debugging jscript event that shows/hides sections based on Opportunity Scope field

(0) ShareShare
ReportReport
Posted on by

I am trying to use a jscript event to show/hide tabs on my Opportunity form based on what is selected in the "Opportunity Scope".  I have made this an OnLoad event, as well as an "OnChange" event for when the Opportunity Scope field is changed.  However, I haven't been able to get the event to work.  I am fairly new to javascript and could use some help debugging.

Here is my code:

function HideShowOpportunityTabs()
{
OppScope = Xrm.Page.getAttribute(“new_OpportunityScope”);
if (OppScope.getValue() != null)
{
if(OppScope.getText()==”Product”)
{
Xrm.Page.ui.tabs.get(“RecurringRevenue”).setVisible(false);
Xrm.Page.ui.tabs.get(“FieldService”).setVisible(false);
}
else if (OppScope.getText()==”Professional Services”)
{
Xrm.Page.ui.tabs.get(“RecurringRevenue”).setVisible(true);
Xrm.Page.ui.tabs.get(“FieldService”).setVisible(true);
}
}
}

When I load the form, I receive the following error:

opportunityscripterror.PNG

The "OnChange" event is not working either.  It does not cause an error, but the sections are not being hidden.

Any help fixing this would be greatly appreciated.  Thanks!

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Need help debugging jscript event that shows/hides sections based on Opportunity Scope field

    That worked!  Thank you so much!

  • Joseph McGregor Macdonald Profile Picture
    597 on at
    RE: Need help debugging jscript event that shows/hides sections based on Opportunity Scope field

    Hi tgiard

    Try using lower case for the field name

    That is replace this line

    OppScope = Xrm.Page.getAttribute("new_OpportunityScope");

    with this

    var OppScope = Xrm.Page.getAttribute("new_opportunityscope");

    Note you should be able to debug the JavaScript in the browser by adding breakpoints. This will assist with narrowing down errors in your code

  • Community Member Profile Picture
    on at
    RE: Need help debugging jscript event that shows/hides sections based on Opportunity Scope field

    Hi Goutam,

    Thank you for your reply.  I tried your suggestion and am now receiving the following error:



    scripterror822.PNG

    Any ideas how I can fix this?

    Thanks!

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Need help debugging jscript event that shows/hides sections based on Opportunity Scope field

    Don't  write  directly into dynamics  webresource editor. Before paste any code you should paste in visual studio Js file or you can use notepad++  and online is editor as well.

    https://js.do/

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Need help debugging jscript event that shows/hides sections based on Opportunity Scope field

    Hi ,

    I think the code copied from browser where double quotation replaced  with double comma.i have replaced all of those double comma to double quotation .

    Now try with this -

    function HideShowOpportunityTabs()

    {

    OppScope = Xrm.Page.getAttribute("new_OpportunityScope");

        if (OppScope.getValue() != null)

           {

              if(OppScope.getText()=="Product")

                 {

      Xrm.Page.ui.tabs.get("RecurringRevenue").setVisible(false);

    Xrm.Page.ui.tabs.get("FieldService").setVisible(false);

                }

            else if(OppScope.getText()=="Professional Services")

             {

    Xrm.Page.ui.tabs.get("RecurringRevenue").setVisible(true);

    Xrm.Page.ui.tabs.get("FieldService").setVisible(true);

              }

         }

    }

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans