Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

JavaScript for hiding sections in Marketing List does not work

Posted on by Microsoft Employee

Hello,

I want to implement a JavaScript, which should hide a section within a tab in the Marketing Lists form.

To try to get this work, I made both sections in the form invisible. Also added it the JavaScript into the Form Properties / Event Handlers.

  • the "members section" is the default section by Microsoft
  • the "members_contacts" is my customized section
  • field "createdfromcode" is "Targeted At" in the form or "Marketing List Member Type" in the entity settings

The JavaScript basically should do:

  1. If the field Targeted At = Account, then show members section and hide members_contacts
  2. else Targeted At = Contact, then show members_contact section and hide members

But it doesn't work, when loading a Marketing List record, it only throws a "Script Error" message which is not every helpful.

What's wrong with that? Many thanks for any helpful advice!

function showHide() {

var createdfromcode =Xrm.Page.getAttribute("createdfromcode").getValue();

if (createdfromcode == Account) {
Xrm.Page.ui.tabs.get("Summary").sections.get("members").setVisible(true);
Xrm.Page.ui.tabs.get("Summary").sections.get("members_contacts").setVisible(false);
}

else if (createdfromcode == Contact) {
Xrm.Page.ui.tabs.get("Summary").sections.get("members_contacts").setVisible(true);
Xrm.Page.ui.tabs.get("Summary").sections.get("members").setVisible(false);
}

}

*This post is locked for comments

  • gdas Profile Picture
    gdas 50,085 on at
    RE: JavaScript for hiding sections in Marketing List does not work

    Hi ,

    So that means the code above does not have any issue.

    I would suggest please close this thread by verifying answers and post your issue in different thread with error message and screenshot of the form properties . This is because the issue you are referencing is completely different with the subject.

    When you put proper subject it will helps others to find the issues /resolution quickly.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JavaScript for hiding sections in Marketing List does not work

    I am using the same code, just only replacing the values for the optionset from text to digit.

    I dont have any javascript available or running in the web resource, this javascript for hide in marketing list is currently the only one.

    This error message throws, after loading a marketing list record and after it successfully hid a section.

    I don't know if it has something to do with the subgrids in the default members section. There are 3 default subgrids Accounts, Contacts and Leads. I think they are also scripted.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: JavaScript for hiding sections in Marketing List does not work

    I would suggest try to  debug your code to find out which line causing issue . You can also find the error details  in F12 debugger console .

    I don't think above code will cause your issue , the error is coming some different function.

    Do you have any other JS register in the web resource?

    BTW when this error you are getting?

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: JavaScript for hiding sections in Marketing List does not work

    Can you please provide full code of your webresource? Do you have other webresources referenced on marketing list form?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JavaScript for hiding sections in Marketing List does not work

    Thank you all,

    it worked by changing the getValue() from text to a digit value.

    But I still get this Script Error message from some reasons:

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

    @url.ofmycrm.com/.../ClientApiWrapper.aspx line 158 > eval:1:1 RunHandlerInternal@url.ofmycrm.com/.../ClientApiWrapper.aspx

    The log file looks like this:

    @aurl.ofmycrm.com/.../ClientApiWrapper.aspx line 158 > eval:1:1
    
    RunHandlerInternal@url.ofmycrm.com/.../ClientApiWrapper.aspx
    
    RunHandlers@url.ofmycrm.com/.../ClientApiWrapper.aspx
    
    OnScriptTagLoaded@url.ofmycrm.com/.../ClientApiWrapper.aspx
    
    AppendScriptTag/scriptTag.onload/<@url.ofmycrm.com/.../ClientApiWrapper.aspx

    Any ideas what cause this?

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: JavaScript for hiding sections in Marketing List does not work

    Hi,

    The "createdfromcode" field is an optionset field which having following options -

    Text                       Value

    ================

    Account                    1

    Contact                     2

    Lead                         4

    So whenever you are doing getValue() it will always return value instead of text. So in your code  you just need to replace the value instead of text like Contact/Account.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: JavaScript for hiding sections in Marketing List does not work

    Try to use following code instead:

    function showHide() {

    var createdfromcode =Xrm.Page.getAttribute("createdfromcode").getValue();

    if (createdfromcode == 1) {

    Xrm.Page.ui.tabs.get("Summary").sections.get("members").setVisible(true);

    Xrm.Page.ui.tabs.get("Summary").sections.get("members_contacts").setVisible(false);

    }

    else if (createdfromcode == 2) {

    Xrm.Page.ui.tabs.get("Summary").sections.get("members_contacts").setVisible(true);

    Xrm.Page.ui.tabs.get("Summary").sections.get("members").setVisible(false);

    }

    }

  • Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: JavaScript for hiding sections in Marketing List does not work

    Hi,

    Which version of CRM you are using?

    recently I worked on + button hide on subgrid with below code, check if you can get the control from parent.

    attaching code for referance,

    function HideAddButtonSubgrid() {
    
       var subGridCtrl = Xrm.Page.getControl("quotedetailsGrid");
    
      // Get the add button
    
       var addButton = window.parent.document.getElementById("quotedetailsGrid_addImageButtonImage");
    
       // Hide the button
    
       $($(addButton).parent().parent()[0]).hide()
    
    }


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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans