Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

I want To Hide Tab for that written code....But Its showing error...given below code

Posted on by 20

function showHideAccountTabs()
{
adminType = Xrm.Page.getAttribute(“cr947_type”);
if (typeof (adminType) != “undefined” && admintType.getValue() != null)
{
if(adminType.getText()==”Customer”)
{
Xrm.Page.ui.tabs.get(“ProspectData”).setVisible(false);
Xrm.Page.ui.tabs.get(“CustomerData”).setVisible(true);
}
else if (adminType.getText()==”Prospect”)
{
Xrm.Page.ui.tabs.get(“ProspectData”).setVisible(true);
Xrm.Page.ui.tabs.get(“CustomerData”).setVisible(false);
}
}
}

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Hi Partner,

    As Mehdi suggested, we should replace Xrm.Page with new formContext.

    By comparing your original code and modified code,

    it seems that names of those two tabs are actually "tab_2" and "tab_3" instead of "ProspectData" and "CustomerData", which could be reason to cause the error you encountered.

    It is glad that your problem has been solved.

    If you had found any answer helped, please kindly mark as verified to close the thread, it will help people who have same question in forum.

    pastedimage1594019519850v1.png

    Regards,

    Clofly

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Hi,

    If you problem resolved, mark this thread verified so that it will be helpful for other community members.

    If found helpful, Please mark my answer verified.

  • Microsoft Forum Profile Picture
    Microsoft Forum 20 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Thank you all for your answers

    the below code was executed

    function showhidetabsss(executionContext)
    {
    var formContext = executionContext.getFormContext();
    var Type = formContext.getAttribute("sai_types").getText();
    var ProspectTab = formContext.ui.tabs.get("tab_2");
    var CustomerTab = formContext.ui.tabs.get("tab_3");
    if(ProspectTab!= null && CustomerTab != null)
    {
    if(Type == "Prospect")
    {
    ProspectTab.setVisible(true);
    CustomerTab.setVisible(false);
    }
    else if (Type == "Customer")
    {
    CustomerTab.setVisible(true);
    ProspectTab.setVisible(false);
    }
    else
    {
    CustomerTab.setVisible(false);
    ProspectTab.setVisible(false);
    }
    }
    }

  • TNS Profile Picture
    TNS 1,195 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Hi,

    It should not show the error, because your code seems fine.Refresh your browser, and still showing the error, check your library and function if it is correct or not.

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Hi, 

    Try the code below, don't forget to add the executionContext as parameter when you register your function: 

    pastedimage1593791280486v1.png

    function showHideAccountTabs(executionContext) {
        var formContext = executionContext.getFormContext();
        var adminType = formContext.getAttribute('“cr947_type”');
    
        if (admintType != null && adminType.getValue() != null) {
            if (adminType.getText() == 'Customer') {
                formContext.ui.tabs.get('ProspectData').setVisible(false);
                formContext.ui.tabs.get('CustomerData').setVisible(true);
            }
            else if (adminType.getText() =='Prospect')
            {
                formContext.ui.tabs.get('ProspectData').setVisible(true);
                formContext.ui.tabs.get('CustomerData').setVisible(false);
            }
        }
    }
    
    

  • Microsoft Forum Profile Picture
    Microsoft Forum 20 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Corrected But Still error is showing

  • Suggested answer
    TNS Profile Picture
    TNS 1,195 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Hi,

    Can you check your this line, I believe you have typed admintType in (admintType.getValue() != null) spelling wrong

    if (typeof (adminType) != “undefined” && admintType.getValue() != null)

    Regards,

    TNS

  • Microsoft Forum Profile Picture
    Microsoft Forum 20 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    One of the scripts for this record has caused an error. For more details, download the log file.

    ReferenceError: showHideAccountTabs is not defined at eval (eval at RunHandlerInternal

  • TNS Profile Picture
    TNS 1,195 on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Hi,

    Can you post the error you are getting.

    Regards,

    TNS

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: I want To Hide Tab for that written code....But Its showing error...given below code

    Hello,

    I see you're using CRM Online. Please do not use Xrm.Page.getAttribute, it is deprecated. Please refer to this sample code: 

    //https://stackoverflow.com/questions/41172313/hiding-a-section-on-dynamics-365-using-js
    //Byron response: 
    function hideOrShow(executionContext){
      var a = executionContext.getFormContext().getAttribute("log_showhide").getValue();
      if (a == 0) {
        Xrm.Page.ui.tabs.get("SUMMARY_TAB").sections.get("sampleSection").setVisible(true);
      } else {
        Xrm.Page.ui.tabs.get("SUMMARY_TAB").sections.get("sampleSection").setVisible(false);
      }
    }

    Refer to this blog for more details about deprecated JavaScript in Dynamics 365: 

    https://community.dynamics.com/crm/b/crm365blog/posts/javascript-deprecated-in-dynamics-365

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans