Dynamics365 “LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control” JavaScript Error










1















We just inherited a MS Dynamics 365 CRM project. We've been making some progress, but it's definitely not our forte.



We've got a form that pre-populates a number of fields. The JavaScript function "setLookupValue" is called to pre-populate the fields. This function is called frequently throughout the solution. It works in all other instances, except for this one field. When the function is called for this particular field, we're receiving the following JavaScript error:




"LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control".




Here's the JS function:



setLookupValue: function (LookupId, Type, Id, Name) 
var lookupReference = ;
lookupReference[0] = ;
lookupReference[0].id = Id;
lookupReference[0].entityType = Type;
lookupReference[0].name = Name;
alert("SET LOOKUP DEBUG: Name = " + Name + ", Type = " + Type + ", ID = " + Id + ", LookupId = " + LookupId);
Xrm.Page.getAttribute(LookupId).setValue(lookupReference);



I feel like the JS function is solid, since it's working in numerous places throughout the solution. This leads me to think it's something related to the parameters (data) being passed in?



I've done a bunch of research online, but am having a tough time getting this sorted.



Thanks in advance for any assistance!










share|improve this question
























  • Can you tell us what values you're passing into the function? If it's working elsewhere it's probably an error there

    – jasonscript
    Nov 16 '18 at 3:45











  • actually based on the error message Cannot add item of typename= to the lookup control it looks like typename is null. You'll need to fix that

    – jasonscript
    Nov 16 '18 at 3:46











  • You can see where I added a debug alert in the JS to track the incoming parameters. The JS function accepts four parameters and I've confirmed all four parameters are being passed in. SET LOOKUP DEBUG: Name = My Business Name, Type = affiliate, ID = 0000000-0000-00000-0000-000000, LookupId = billingaffiliateid (I redacted the actual guid.)

    – Josh Greenberg
    Nov 16 '18 at 4:15















1















We just inherited a MS Dynamics 365 CRM project. We've been making some progress, but it's definitely not our forte.



We've got a form that pre-populates a number of fields. The JavaScript function "setLookupValue" is called to pre-populate the fields. This function is called frequently throughout the solution. It works in all other instances, except for this one field. When the function is called for this particular field, we're receiving the following JavaScript error:




"LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control".




Here's the JS function:



setLookupValue: function (LookupId, Type, Id, Name) 
var lookupReference = ;
lookupReference[0] = ;
lookupReference[0].id = Id;
lookupReference[0].entityType = Type;
lookupReference[0].name = Name;
alert("SET LOOKUP DEBUG: Name = " + Name + ", Type = " + Type + ", ID = " + Id + ", LookupId = " + LookupId);
Xrm.Page.getAttribute(LookupId).setValue(lookupReference);



I feel like the JS function is solid, since it's working in numerous places throughout the solution. This leads me to think it's something related to the parameters (data) being passed in?



I've done a bunch of research online, but am having a tough time getting this sorted.



Thanks in advance for any assistance!










share|improve this question
























  • Can you tell us what values you're passing into the function? If it's working elsewhere it's probably an error there

    – jasonscript
    Nov 16 '18 at 3:45











  • actually based on the error message Cannot add item of typename= to the lookup control it looks like typename is null. You'll need to fix that

    – jasonscript
    Nov 16 '18 at 3:46











  • You can see where I added a debug alert in the JS to track the incoming parameters. The JS function accepts four parameters and I've confirmed all four parameters are being passed in. SET LOOKUP DEBUG: Name = My Business Name, Type = affiliate, ID = 0000000-0000-00000-0000-000000, LookupId = billingaffiliateid (I redacted the actual guid.)

    – Josh Greenberg
    Nov 16 '18 at 4:15













1












1








1








We just inherited a MS Dynamics 365 CRM project. We've been making some progress, but it's definitely not our forte.



We've got a form that pre-populates a number of fields. The JavaScript function "setLookupValue" is called to pre-populate the fields. This function is called frequently throughout the solution. It works in all other instances, except for this one field. When the function is called for this particular field, we're receiving the following JavaScript error:




"LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control".




Here's the JS function:



setLookupValue: function (LookupId, Type, Id, Name) 
var lookupReference = ;
lookupReference[0] = ;
lookupReference[0].id = Id;
lookupReference[0].entityType = Type;
lookupReference[0].name = Name;
alert("SET LOOKUP DEBUG: Name = " + Name + ", Type = " + Type + ", ID = " + Id + ", LookupId = " + LookupId);
Xrm.Page.getAttribute(LookupId).setValue(lookupReference);



I feel like the JS function is solid, since it's working in numerous places throughout the solution. This leads me to think it's something related to the parameters (data) being passed in?



I've done a bunch of research online, but am having a tough time getting this sorted.



Thanks in advance for any assistance!










share|improve this question
















We just inherited a MS Dynamics 365 CRM project. We've been making some progress, but it's definitely not our forte.



We've got a form that pre-populates a number of fields. The JavaScript function "setLookupValue" is called to pre-populate the fields. This function is called frequently throughout the solution. It works in all other instances, except for this one field. When the function is called for this particular field, we're receiving the following JavaScript error:




"LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control".




Here's the JS function:



setLookupValue: function (LookupId, Type, Id, Name) 
var lookupReference = ;
lookupReference[0] = ;
lookupReference[0].id = Id;
lookupReference[0].entityType = Type;
lookupReference[0].name = Name;
alert("SET LOOKUP DEBUG: Name = " + Name + ", Type = " + Type + ", ID = " + Id + ", LookupId = " + LookupId);
Xrm.Page.getAttribute(LookupId).setValue(lookupReference);



I feel like the JS function is solid, since it's working in numerous places throughout the solution. This leads me to think it's something related to the parameters (data) being passed in?



I've done a bunch of research online, but am having a tough time getting this sorted.



Thanks in advance for any assistance!







javascript dynamics-crm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 23:02









Arun Vinoth

10k132658




10k132658










asked Nov 15 '18 at 21:23









Josh GreenbergJosh Greenberg

27816




27816












  • Can you tell us what values you're passing into the function? If it's working elsewhere it's probably an error there

    – jasonscript
    Nov 16 '18 at 3:45











  • actually based on the error message Cannot add item of typename= to the lookup control it looks like typename is null. You'll need to fix that

    – jasonscript
    Nov 16 '18 at 3:46











  • You can see where I added a debug alert in the JS to track the incoming parameters. The JS function accepts four parameters and I've confirmed all four parameters are being passed in. SET LOOKUP DEBUG: Name = My Business Name, Type = affiliate, ID = 0000000-0000-00000-0000-000000, LookupId = billingaffiliateid (I redacted the actual guid.)

    – Josh Greenberg
    Nov 16 '18 at 4:15

















  • Can you tell us what values you're passing into the function? If it's working elsewhere it's probably an error there

    – jasonscript
    Nov 16 '18 at 3:45











  • actually based on the error message Cannot add item of typename= to the lookup control it looks like typename is null. You'll need to fix that

    – jasonscript
    Nov 16 '18 at 3:46











  • You can see where I added a debug alert in the JS to track the incoming parameters. The JS function accepts four parameters and I've confirmed all four parameters are being passed in. SET LOOKUP DEBUG: Name = My Business Name, Type = affiliate, ID = 0000000-0000-00000-0000-000000, LookupId = billingaffiliateid (I redacted the actual guid.)

    – Josh Greenberg
    Nov 16 '18 at 4:15
















Can you tell us what values you're passing into the function? If it's working elsewhere it's probably an error there

– jasonscript
Nov 16 '18 at 3:45





Can you tell us what values you're passing into the function? If it's working elsewhere it's probably an error there

– jasonscript
Nov 16 '18 at 3:45













actually based on the error message Cannot add item of typename= to the lookup control it looks like typename is null. You'll need to fix that

– jasonscript
Nov 16 '18 at 3:46





actually based on the error message Cannot add item of typename= to the lookup control it looks like typename is null. You'll need to fix that

– jasonscript
Nov 16 '18 at 3:46













You can see where I added a debug alert in the JS to track the incoming parameters. The JS function accepts four parameters and I've confirmed all four parameters are being passed in. SET LOOKUP DEBUG: Name = My Business Name, Type = affiliate, ID = 0000000-0000-00000-0000-000000, LookupId = billingaffiliateid (I redacted the actual guid.)

– Josh Greenberg
Nov 16 '18 at 4:15





You can see where I added a debug alert in the JS to track the incoming parameters. The JS function accepts four parameters and I've confirmed all four parameters are being passed in. SET LOOKUP DEBUG: Name = My Business Name, Type = affiliate, ID = 0000000-0000-00000-0000-000000, LookupId = billingaffiliateid (I redacted the actual guid.)

– Josh Greenberg
Nov 16 '18 at 4:15












2 Answers
2






active

oldest

votes


















0














Similar issue discussed in community here and here.



  1. Make sure you are passing entity logical name in entityType parameter ie all small characters

  2. Also entity name should be singular not plural like ending with ‘s’ or ‘es’

  3. Compare the snippet calling this method between working & non-working code





share|improve this answer






























    0














    Thank you to everyone who provided helpful insight. I was able to fix the issue by closely examining the JS lookup calls that were working.



    Best I can tell, what "LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control” really means is that Dynamics cannot find an entity type matching the name you're passing in.



    In my case, I was passing in "affiliate". Due to an inconsistency in the way the entities were named in this solution, there was a prefix on the Affiliate entity name. The correct entity name needed for the function is displayed on the Entity Definition page.



    So ultimately, the entity name being passing in to the JS function for Type was incorrect. Once I added the prefix to correct the type name, the lookup call started working.






    share|improve this answer























    • FYI all custom entities within CRM should have a prefix

      – jasonscript
      Nov 16 '18 at 7:05










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328088%2fdynamics365-lookup-control-error-cannot-add-item-of-typename-to-the-lookup-co%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Similar issue discussed in community here and here.



    1. Make sure you are passing entity logical name in entityType parameter ie all small characters

    2. Also entity name should be singular not plural like ending with ‘s’ or ‘es’

    3. Compare the snippet calling this method between working & non-working code





    share|improve this answer



























      0














      Similar issue discussed in community here and here.



      1. Make sure you are passing entity logical name in entityType parameter ie all small characters

      2. Also entity name should be singular not plural like ending with ‘s’ or ‘es’

      3. Compare the snippet calling this method between working & non-working code





      share|improve this answer

























        0












        0








        0







        Similar issue discussed in community here and here.



        1. Make sure you are passing entity logical name in entityType parameter ie all small characters

        2. Also entity name should be singular not plural like ending with ‘s’ or ‘es’

        3. Compare the snippet calling this method between working & non-working code





        share|improve this answer













        Similar issue discussed in community here and here.



        1. Make sure you are passing entity logical name in entityType parameter ie all small characters

        2. Also entity name should be singular not plural like ending with ‘s’ or ‘es’

        3. Compare the snippet calling this method between working & non-working code






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 22:57









        Arun VinothArun Vinoth

        10k132658




        10k132658























            0














            Thank you to everyone who provided helpful insight. I was able to fix the issue by closely examining the JS lookup calls that were working.



            Best I can tell, what "LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control” really means is that Dynamics cannot find an entity type matching the name you're passing in.



            In my case, I was passing in "affiliate". Due to an inconsistency in the way the entities were named in this solution, there was a prefix on the Affiliate entity name. The correct entity name needed for the function is displayed on the Entity Definition page.



            So ultimately, the entity name being passing in to the JS function for Type was incorrect. Once I added the prefix to correct the type name, the lookup call started working.






            share|improve this answer























            • FYI all custom entities within CRM should have a prefix

              – jasonscript
              Nov 16 '18 at 7:05















            0














            Thank you to everyone who provided helpful insight. I was able to fix the issue by closely examining the JS lookup calls that were working.



            Best I can tell, what "LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control” really means is that Dynamics cannot find an entity type matching the name you're passing in.



            In my case, I was passing in "affiliate". Due to an inconsistency in the way the entities were named in this solution, there was a prefix on the Affiliate entity name. The correct entity name needed for the function is displayed on the Entity Definition page.



            So ultimately, the entity name being passing in to the JS function for Type was incorrect. Once I added the prefix to correct the type name, the lookup call started working.






            share|improve this answer























            • FYI all custom entities within CRM should have a prefix

              – jasonscript
              Nov 16 '18 at 7:05













            0












            0








            0







            Thank you to everyone who provided helpful insight. I was able to fix the issue by closely examining the JS lookup calls that were working.



            Best I can tell, what "LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control” really means is that Dynamics cannot find an entity type matching the name you're passing in.



            In my case, I was passing in "affiliate". Due to an inconsistency in the way the entities were named in this solution, there was a prefix on the Affiliate entity name. The correct entity name needed for the function is displayed on the Entity Definition page.



            So ultimately, the entity name being passing in to the JS function for Type was incorrect. Once I added the prefix to correct the type name, the lookup call started working.






            share|improve this answer













            Thank you to everyone who provided helpful insight. I was able to fix the issue by closely examining the JS lookup calls that were working.



            Best I can tell, what "LOOKUP CONTROL ERROR: Cannot add item of typename= to the lookup control” really means is that Dynamics cannot find an entity type matching the name you're passing in.



            In my case, I was passing in "affiliate". Due to an inconsistency in the way the entities were named in this solution, there was a prefix on the Affiliate entity name. The correct entity name needed for the function is displayed on the Entity Definition page.



            So ultimately, the entity name being passing in to the JS function for Type was incorrect. Once I added the prefix to correct the type name, the lookup call started working.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 16 '18 at 5:44









            Josh GreenbergJosh Greenberg

            27816




            27816












            • FYI all custom entities within CRM should have a prefix

              – jasonscript
              Nov 16 '18 at 7:05

















            • FYI all custom entities within CRM should have a prefix

              – jasonscript
              Nov 16 '18 at 7:05
















            FYI all custom entities within CRM should have a prefix

            – jasonscript
            Nov 16 '18 at 7:05





            FYI all custom entities within CRM should have a prefix

            – jasonscript
            Nov 16 '18 at 7:05

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328088%2fdynamics365-lookup-control-error-cannot-add-item-of-typename-to-the-lookup-co%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線