locked
CRM 2013 - Form customization - 'Unable to get property 'setVisible' of undefined or null reference' RRS feed

  • Question

  • Hi all

    Firstly, thank-you (heaps) in advance for your patience with me, I am not a developer and am not entirely up with the lingo.

    I have just rearranged the New Opportunity form per company per my boss' hand sketch and something I have done has caused an error. 

    When I now go to open a New Opportunity, after the window loads the below error pops up. What information do I need to give you to help me resolve this issue?

    Thanks again for any pointers. :)

    EDIT: I have gone through the Form Properties > Events > Event Handlers > Edit to check which are the fields they mention. Then cross checked these with all the fields we have included in the form and they all appear to be there. I might not be looking at the right part though. 



    • Edited by Jalanda Friday, July 11, 2014 4:32 AM Updated title
    Friday, July 11, 2014 4:04 AM

Answers

  • Hi,

    There you go! You have the line:

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

    I think while rearranging you might have removed/rearranged/renamed the "tab_7" tab. You might want to check that and remove this line if needed. That should hopefully fix your error.


    Admin QuikView Solution for CRM 2013

    • Marked as answer by Jalanda Friday, July 11, 2014 5:25 AM
    Friday, July 11, 2014 5:10 AM

All replies

  • Hi,

    This is generally caused when you reference a field in your form JavaScript and you actually do not have that field on form. When you said you rearranged the fields, did you remove any fields? Or maybe rearrange some sections? If yes, then that is the reason.

    Like you said, you get the error when the page loads. So, you might want to check the Form OnLoad script to see if any field/section is referenced which is actually not present on the form or rearranged. If you provide your OnLoad script here, we might be able to assist you.


    Admin QuikView Solution for CRM 2013

    Friday, July 11, 2014 4:32 AM
  • Thanks, yes I did rearrange, add and remove. I checked the OnLoad Script (or what I assume is the OnLoad script) and am somewhat sure that all the fields are present. Is this the OnLoad script?

       

    /*ONLOAD opportunity, ONCHANGE est revenue */

    function CalcWeightedRevenue() {
        var estrevenue = Xrm.Page.getAttribute("estimatedvalue").getValue();
        var probability = Xrm.Page.getAttribute("closeprobability").getValue();
        var weightedrev = Xrm.Page.getAttribute("pnl_weightedrevenue");

        //alert(estrevenue);
        //alert(probability);

        if (estrevenue > 0 && probability > 0) {
            weightedrev.setValue(estrevenue * probability / 100);
        } else {
            weightedrev.setValue(0);
        }

    }

    I interpret this as requiring the following fields:

    - Est. Revenue

    - Probability

    - Weighted Revenue (by the way this is the only field where the box representing where the user enters information, is actually light blue instead of white)

    - I'm not sure what 'closeprobability' and 'estimatedvalue' are.

    - Below is that section of the form as it appears currently.



    • Edited by Jalanda Friday, July 11, 2014 4:43 AM
    Friday, July 11, 2014 4:35 AM
  • Hello,

    There is no code which is setting visibility so may be there is some other code which is creating issue.

    To avoid this type of error best option is to first check field availability on form and then apply your logic like below

    var estrevenue =(Xrm.Page.getAttribute("estimatedvalue")!=null? Xrm.Page.getAttribute("estimatedvalue").getValue():null);


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, July 11, 2014 4:43 AM
    Moderator
  • Hi,

    I don't see any fields that uses .setVisible(). So, my guess is you might have something On Change of "pnl_weightedrevenue". Do you have only this script on Form Load, or anything else? Can you check if you have anything On Change of "pnl_weightedrevenue"?


    Admin QuikView Solution for CRM 2013

    Friday, July 11, 2014 4:48 AM
  • I think you are getting closer. 

    The weighted revenue field is one that has acted funnily in the past. The boss told me that it only ever updated/populated after he finished filling out the new opportunity form, and then saved and closed and went back into it. 

    This is what the various (probably) relevant properties look like and the script for the one I've circled is underneath. 

    /*onload opportunity*/

    function updateCompletedProductsSubGrid() {

        //This will get the related completed products grid details and store in a variable.
        var relatedCompletedProducts = document.getElementById("CompletedProducts");

        //Initializing the lookup field to store in an array.
        var lookupfield = new Array;

        //Get the lookup field
        lookupfield = Xrm.Page.getAttribute("customerid").getValue();

        //This will get the lookup field guid if there is value present in the lookup
        if (lookupfield != null && lookupfield[0].entityType == "account") {
            var lookupid = lookupfield[0].id;
        }
            //Else the function will hide the SubGrid and no further code will be executed.
        else {
            Xrm.Page.ui.tabs.get("tab_7").setVisible(false);
            return;
        }

        //This method is to ensure that grid is loaded before processing.
        if (relatedCompletedProducts == null || relatedCompletedProducts.readyState != "complete") {
            //This statement is used to wait for 2 seconds and recall the function until the grid is loaded.
            setTimeout('updateCompletedProductsSubGrid()', 2000);
            return;
        }

        //This is the fetch xml code which will retrieve all the completed products related to the account selected for the opportunity.
        var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
        fetchXml += "<entity name='pnl_completedproduct'>";
        fetchXml += "<attribute name='pnl_name'/>";
        fetchXml += "<attribute name='pnl_producttype'/>";
        fetchXml += "<attribute name='pnl_consultant'/>";
        fetchXml += "<attribute name='pnl_completeddate'/>";
        fetchXml += "<attribute name='pnl_comments'/>";
        fetchXml += "<order descending='false' attribute='pnl_name'/>";
        fetchXml += "<filter type='and'>";
        fetchXml += "<condition attribute='pnl_accountid' value='" + lookupid + "' uitype='account' operator='eq'/>";
        fetchXml += "</filter>";
        fetchXml += "</entity>";
        fetchXml += "</fetch>";

        //Setting the fetch xml to the sub grid.
        relatedCompletedProducts.control.SetParameter("fetchXml", fetchXml);

        //This statement will refresh the sub grid after making all modifications.
        relatedCompletedProducts.control.refresh();
    }

    Friday, July 11, 2014 5:04 AM
  • Hi,

    There you go! You have the line:

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

    I think while rearranging you might have removed/rearranged/renamed the "tab_7" tab. You might want to check that and remove this line if needed. That should hopefully fix your error.


    Admin QuikView Solution for CRM 2013

    • Marked as answer by Jalanda Friday, July 11, 2014 5:25 AM
    Friday, July 11, 2014 5:10 AM
  • <3 You're a legend. 

    Does the code tell you if this will break anything else? Is Tab 7 there for anything else? Where do I find Tab 7 to add it back in? If it is not required, why would it be in the code? If possible I'd rather add Tab 7 back in than touch the code. 

    EDIT: Nevermind I figured it out. Well how to add a new tab and rename it as tab_7. I still don't know what tab_7 was there for in the first place, but at least no error now! 

    I love this guy! Big kudos. 

    =]

    • Edited by Jalanda Friday, July 11, 2014 5:26 AM
    Friday, July 11, 2014 5:13 AM
  • Hi,

    Did you remove any tab while you were re-arranging fields? If yes, tab_7 might have been deleted then. If you moved all the fields from tab_7 to other tabs/sections and then removed the empty tab (hopefully) based on what your boss said, not having it on the form shouldn't be a big issue. I believe it's due to some changed requirement that you re-arranged the fields. Unless we know what the business requirement is, we cant really say if you might have broken anything. Either way, it's only going to be some fields being shown/hidden if at all anything breaks.

    Also, just for your information, all the line of code did was to hide the tab.


    Admin QuikView Solution for CRM 2013


    Friday, July 11, 2014 5:34 AM
  • Hi, 

    Thanks, yes I did delete a whole bunch of generic looking tabs; there were about 6 or so of them because the boss asked me to get rid of the wasted space. With your help, I have added in a new tab which defaulted to being called tab_5; I renamed it to tab_7 and the error has gone. 

    Only time will tell if I have created any other issues!

    Thanks so much for your help I have bookmarked your site and will be doing as much reading up as I can! (I'm supposed to become our resident CRM expert)

    Thanks again

    Friday, July 11, 2014 5:38 AM
  • Glad to have helped! :) Cheers!

    Admin QuikView Solution for CRM 2013

    Friday, July 11, 2014 5:49 AM