locked
CRM 2016 JS Set Lookup type mismatch error RRS feed

  • Question

  • When I set the lookup in java script I get a type mismatch error after all Java has run.

    Here is the reults of a function I have to create the array and return it to the setvalue statement.

    return

    [{ id: entity.attributes[field].id, name: entity.attributes[field].name, entityType: entity.attributes[field].logicalName}]

    The strange thing is the lookup works I can click the link and go to the record selected.

    Any guidance would be appreciated.

    Monday, January 18, 2016 4:52 PM

Answers

  • The latest version of XRMTOOLKIT and the latest update for CRM2016 on premise seems to have fixed my issue.

    • Marked as answer by bbuchanan Tuesday, January 17, 2017 2:56 PM
    Monday, November 21, 2016 2:21 PM

All replies

  • Hi,

    Can you provide more code around this? What is the "entity" here for example and how is it retrieved. The syntax looks more like a c# plugin than js to me.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Tuesday, January 19, 2016 7:38 AM
  • Hi ,

    While setting lookup value  Check you are passing the correct  lookup value.

    Below code is working for me in MS CRM 2016 online.

     Xrm.Page.getAttribute("parentcustomerid").setValue([{
                id: "9C33D98E-2FAD-E511-80DE-6C3BE5A8380C",
                name: "A. Datum Corporation (sample)",
                entityType: "account"
            }]);
     

    Regards,


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Tuesday, January 19, 2016 1:07 PM
  • Rickard here is all the code. Mohammad the lookup value is correct because even though I get the error the lookup link works.

    function Default_BidderDetails() {
        if (Xrm.Page.getAttribute("esi_gpprocesspayment").getValue() == false) {
            if (Xrm.Page.getAttribute("esi_bidregbuyerid").getValue() != null) {
                var fetchxml = "<fetch mapping='logical' count='50' version='1.0'><entity name='esi_bidderregistration'><attribute name='esi_biddercompanyid' /><attribute name='esi_biddercontactid' /><attribute name='esi_individualordealer' /><filter><condition attribute='esi_bidderregistrationid' operator='eq' value=' " + Xrm.Page.getAttribute('esi_bidregbuyerid').getValue()[0].id + "' /></filter><link-entity name='contact' from='contactid' to='esi_biddercontactid'><attribute name='fullname' /></link-entity></entity></fetch>"
                var aoFetchResult = XrmServiceToolkit.Soap.Fetch(fetchxml);
                if (aoFetchResult[0] != null) {
                    if (aoFetchResult.length == 1) {
                        var beRetLot = aoFetchResult[0];
                       
                        if (beRetLot != null) {

                           
                            SetValue("esi_buyerid", XrmFieldTest(beRetLot, "esi_biddercontactid"));
                           
                            SetValue("esi_buyertype", XrmFieldTest(beRetLot, "esi_individualordealer"));
                            SetValue("esi_buyercompanyid", XrmFieldTest(beRetLot, "esi_biddercompanyid"));
                        }
                    }
                }

                    } else {
                        SetValue("esi_buyerid", null);
                        SetValue("esi_buyertype", null);
                        SetValue("esi_buyercompanyid", null);
                 
            }
        }

    }

    function XrmFieldTest(entity, field, entityname) {
        if (entity.attributes[field]) {
            if (entity.attributes[field].type == "EntityReference") {
                          
                if (entity.attributes[field].logicalName == "") {
                    return [{ id: entity.attributes[field].id, name: entityname, entityType: entity.attributes[field].name}];
                } else {
                    return [{ id: entity.attributes[field].id , name: entity.attributes[field].name, LogicalName: entity.attributes[field].logicalName, entityType: entity.attributes[field].logicalName}];
                }
           
            } else {
            return entity.attributes[field].value;
            }
        } else {
            return null
        }
    }

    function SetValue(ctr_name, value) {
        Xrm.Page.getAttribute(ctr_name).setValue(value);
        if (Xrm.Page.getAttribute(ctr_name).getIsDirty() == true) {
            Xrm.Page.getAttribute(ctr_name).setSubmitMode("always");
        } else {
            Xrm.Page.getAttribute(ctr_name).setSubmitMode("dirty");
        }
    }

    Tuesday, January 19, 2016 3:00 PM
  • Here is the stack trace from the browser.

    stack "TypeError: Type mismatch\n   at Mscrm.Proxies.PresenceControlProxy.prototype.getStatus (http://rmcrm2016/Auctions/_common/global.ashx?ver=324522911:27700:647587)\n   at Mscrm.TurboForm.Control.ViewModel.LookupViewModel.prototype.$HK_5 (http://rmcrm2016/_static/form/formcontrols.js?ver=324522911:14449:13)\n   at Anonymous function (http://rmcrm2016/Auctions/_common/global.ashx?ver=324522911:5:298)\n   at Anonymous function (http://rmcrm2016/Auctions/_common/global.ashx?ver=324522911:27700:650444)\n   at Anonymous function (http://rmcrm2016/Auctions/_common/global.ashx?ver=324522911:27700:764186)"

    Tuesday, January 19, 2016 6:09 PM
  • OK now I'm getting somewhere I hope.

    Debugging in Chrome gives me a line number in global.ashx It is related to the following

    Type.registerNamespace("Mscrm"); it says registernamespace is undefined.

    Tuesday, January 19, 2016 6:55 PM
  • Further update. It appears the XRMtoolkit I am using for soap fetches is not compatible with CRM 2016. Now I need to find examples of fetch using JS in 2016.

    Tuesday, January 19, 2016 9:10 PM
  • I'm facing a similar issue,

    do you have any fix for this problem?

    I've tried using XRMServiceToolkit 2.2.1 , still no luck.

    -ben

    Sunday, November 20, 2016 4:39 AM
  • Hi,

    Sorry, I totally missed this update. Did you ever sort this out?

    It's sort of hard do say what's wrong in you code since you made sub functions that handle stuff. What happens if you hard code some values and tries it, or as you said that the fetch part is the problem have a look at using the webAPI instead.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Monday, November 21, 2016 12:10 PM
  • The latest version of XRMTOOLKIT and the latest update for CRM2016 on premise seems to have fixed my issue.

    • Marked as answer by bbuchanan Tuesday, January 17, 2017 2:56 PM
    Monday, November 21, 2016 2:21 PM