Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

CRM 2011: Load a Lookup field from another Lookup field's attribute value.

$
0
0

I just want a contact lookup on a form, but then I want to also put a disabled lookup field next to it that contains the contacts parent account and load it via JavaScript.  I cannot get the JavaScript down.

Here's the JavaScript function I have come up with.  But it doesn't work.  The outter logic works, but I cannot get the attribute of the entity, which should contain the account id of the contact's parent account.  But it always shows up undefined no mater how I adjust or rewrite the code.  I think I am missing something simple here. 

I am passing in the contact's GUID, it pulls the contact, but I cannot get the GUID of the parentcustomerid, which is the GUID for the parent account for this contact.

I suspect the line [lookupValue[0].id = attribute.AccountId;] is the issue.  I don't know how to get the GUID from the contact that has been returned from the SDK call.

 RetrieveContact = function (id) {
        if (debug) { alert('RetrieveContact Id:' + id); }

        var lookupValue = new Array();

        SDK.JQuery.retrieveRecord(
            id,
            "Contact",
            null, null,
            function (contact) {
                for(attribute in contact) {
                    switch (attribute) {
                        case "ParentCustomerId":
                            alert('found attribute');
                            lookupValue[0] = new Object();
                            lookupValue[0].id = attribute.AccountId;
                            lookupValue[0].name = attribute.name;
                            lookupValue[0].entityType = "Account";

                            if (debug) { alert('loaded lookup'); } 
                            Xrm.Page.getAttribute("new_parentaccount").setValue(lookupValue)                                            
                            break;
                        default:
                            break;
                    };
                }
            },
            errorHandler
        );
    }
Any thoughts or suggestions here? This seems simple but I cannot get it to work. I think I might be missing something in regards to how to pull the attribute from the contact to get the GUID, which is what I need to set the parent account lookup field.


Jon Gregory Rothlander


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>