Skip to content

Instantly share code, notes, and snippets.

@stimms
Created March 29, 2019 04:25
Show Gist options
  • Save stimms/1d1d0691f9d1174ef98df11eea083628 to your computer and use it in GitHub Desktop.
Save stimms/1d1d0691f9d1174ef98df11eea083628 to your computer and use it in GitHub Desktop.
// option 1 - async
async function draw() {
    var contactId = parent.Xrm.Page.data.entity.getId();
    connections = await getConnectionsByContactId(contactId);
}
async function getConnectionsByContactId(contactId) {
    const result = await Xrm.WebApi.retrieveRecord("contact", contactId,
        `?$expand=contact_connections1($select=_record2id_value,connectionid,name,record2objecttypecode,entityimage_url)
        &$select=contactid,fullname,entityimage_url`);
return result;
}
// option 2 - promises
function draw() {
    const contactId = parent.Xrm.Page.data.entity.getId();
    connections = getConnectionsByContactId(contactId).then(connections=> {
//do your drawing here
});
}
function getConnectionsByContactId(contactId) {
    return Xrm.WebApi.retrieveRecord("contact", contactId,
        `?$expand=contact_connections1($select=_record2id_value,connectionid,name,record2objecttypecode,entityimage_url)
        &$select=contactid,fullname,entityimage_url`)
        .then(resultToken => {
            return resultToken;
        })
        .catch(error => {
            throw error;
        });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment