Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

[JS] Resolving account lookupfield from a contact lookupfield

$
0
0

Hi,

when a user selects a contact, the related account should be set in the corresponding account lookup.

Everything works fine, but when i save the record, the contact field value is getting deleted.

Any suggestions?

    function setRelatedAccount() {

        try {

            var check = Xrm.Page.getAttribute(incident_account).getValue();

            if (check != null) {

                console.log("Account already set!");

            }

            else {

                var contact_field = Xrm.Page.getAttribute(incident_contact);

                if (contact_field != null) {

                    var contact_id = Xrm.Page.getAttribute(incident_contact).getValue()[0].id;

                    if (contact_id != null) {

                        contact = Xrm.Page.getAttribute(incident_contact).getValue();

                        retrieveAccountForContact("ContactSet", contact_id); //get the account for a contact

                        Xrm.Page.getAttribute(incident_tmpaccount).setValue(account);

                        Xrm.Page.getAttribute(incident_tmpcontact).setValue(contact);

                    }

                }

                else {

                    console.log("Contact Field not available!");

                }

            }

        } catch (ex) {

            console.log(ex);

        }

    }

Viewing all articles
Browse latest Browse all 46379

Trending Articles



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