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 :
Microsoft Dynamics CRM (Archived)

Hidden Tabs and Required Fields Upon Made Visible

(0) ShareShare
ReportReport
Posted on by 195

We are trying to expand on the opportunity entity to the point where a hidden tab could be revealed using script and inside that hidden tab the required fields that are set wouldn't prevent saving the record until the tab has become visible. Any thoughts?

*This post is locked for comments

I have the same question (0)
  • MDoddio73 Profile Picture
    1,910 on at

    This is easy to accomplish, but when would you like the hidden tab to become visible?

  • jsm1972 Profile Picture
    195 on at

    Once the opportunity sales step has been changed to 'Qualified' and saved (step 3), we would like for the hidden tab (requiring much more detailed information) to expand and expose those fields- some of which would then become mandatory.

  • MDoddio73 Profile Picture
    1,910 on at

    Okay. This can be accomplished by creating a JScript Web Resource. In this JScript file, you will need to create a JavaScript function, include the code you need to show/hide tabs/Set Require Level methods described in the Dynamics CRM SDK (Xrm.Page.ui). Once the function is built, you can save the Web Resource in CRM, then access that resource in the Opportunity Form Properties dialog. Add the Resource to the Opportunity, then find the Sales Step attribute and add the function to the OnChange event.

    I'll post some code in a few to get you started...

  • Verified answer
    MDoddio73 Profile Picture
    1,910 on at

    This should help get you started. Please refer to the Dynamics CRM SDK for more info:

    function salesStepOnLoad() {

        var statusReason = Xrm.Page.getAttribute("salesstep").getValue();

        switch (parseInt(salesStep, 10)) {

            /* Assumes that the integer value for the Sales Step option you wish to trigger the show/hide is 3 or higher */

            case 3:

            case 4:

            case 5:

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

                Xrm.Page.getAttribute("thenameofanyfieldrequired").setRequiredLevel("required"); /* All attribute names need to be reference in lowercase */

                break;

            default:

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

                Xrm.Page.getAttribute("thenameofanyfieldrequired").setRequiredLevel("none");

                break;

        }

    }

     

    function salesStepOnChange(context) {

        var salesStep = context.getEventSource().getValue();

        switch (parseInt(salesStep, 10)) {

            /* Assumes that the integer value for the Sales Step option you wish to trigger the show/hide is 3 or higher */

            case 3:

            case 4:

            case 5:

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

                Xrm.Page.getAttribute("thenameofanyfieldrequired").setRequiredLevel("required"); /* All attribute names need to be reference in lowercase */

                break;

            default:

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

                Xrm.Page.getAttribute("thenameofanyfieldrequired").setRequiredLevel("none");

                break;

        }

    }

  • jsm1972 Profile Picture
    195 on at

    THat was a huge help. Thank you. I think we are off and running.

  • jsm1972 Profile Picture
    195 on at

    Ok, so we hit a little road block. We are getting an error, and are wondering if its caused by the field we are looking at being an option field? So our options for salesstep is for example 1. Suspect. The event should take place when changed to number 3, or 3. Qualified. Is the script needing just an integer vs. the whole value?

    function salesStepOnLoad() {

       var salesStep = Xrm.Page.data.entity.attributes.get("new_salesstep").getValue();

       switch (parseInt(salesStep, 10)) {

           case 3:

           case 4:

           case 5:

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

  • MDoddio73 Profile Picture
    1,910 on at

    What's the error you're getting?

    You only need to use the Integer value in the code, not the text value. That said, the CRM db stores the values of an Optionset as an integer, however, the value passed to the code using .getValue() method is actually a text value (so technically, Optionset value integer value for "3. Qualified" comes into the salesStep variable as "3", not 3, which is why you need to use parseInt() for the salesStep variable.

    Anyways, the code you pasted looks okay, but can you paste the entire function, as the error may be further down than what you've shown...

  • jsm1972 Profile Picture
    195 on at

    The error says:

    There was an error with the field's customized event. Field: new_disposal, Event:onchange, Error:'salesStepOnChange' is undefined

  • MDoddio73 Profile Picture
    1,910 on at

    Looks like you added the salesStepOnChange function to the OnCHange event of the Disposal field. If the function wasn't added to your Web Resource JScript file, then this error will appear.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/globalsearch/?q=how+to+hack++in+roblox+train+to+fight" - Nested quantifier +.