Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Unanswered

Trying to find out how to insert a child lookup into a parent lookup field value using xrm.webapi

Posted on by 4
I am not sure using javascript we can create an object that will add its child lookup value  into it.
Any  help would be appreciated on this topic.
Thanks
here I am trying to add signatureLookup value to the field of queue object i.e. /emailsignature/.
Categories:
  • Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Trying to find out how to insert a child lookup into a parent lookup field value using xrm.webapi
    Hi,
     
    Auto populating the queue to the From field can be achieved with the following code.

    function onload(executionContext) {
        var fetchXML = `?fetchXml=
    <fetch mapping='logical'>
       <entity name='queue'>
             <filter type='and'>
                <condition attribute='name' operator='eq' value='<Queue name>'/>
             </filter>
       </entity>
    </fetch>`;
        Xrm.WebApi.retrieveMultipleRecords("queue", fetchXML).then(
            function success(result) {
                var lookup = new Array();
                var lookupvalue = new Object();
                lookupvalue.id = result.entities[0].queueid;
                lookupvalue.name = result.entities[0].name;
                lookupvalue.entityType = "queue";
                lookup[0] = lookupvalue;
                executionContext.getFormContext().getAttribute("from").setValue(lookup);
            },
            function (error) {
                console.log(error.message);
            }
        );
    }
     
    Best Regards,
    Dengliang Li
     
  • AK-24060956-0 Profile Picture
    AK-24060956-0 4 on at
    Trying to find out how to insert a child lookup into a parent lookup field value using xrm.webapi
    Thanks Dengliang, but according to this post, we are copying the value from a system user lookup field to another system user lookup field. 
    However, what I am trying to achieve here is Queue is a parent entity here and there is a emailsignature lookup field under Queue record that I am fetching using xrm.webapi via fetchxml.
    after this fetch, I want to populate this Queue record to a From field which is a lookup for Queue records. 
    I am attaching the Queue record to From field using following snippet - 
    However this Lookup[0] Object from lookup array is a brand new record of Queue entity that is not holding any reference to emailsignature record inside it.
    can we somehow reference the emailsignature record inside lookup[0] record object ?
  • Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Trying to find out how to insert a child lookup into a parent lookup field value using xrm.webapi
    Hi,
     
    Please refer to the following link.
    Best Regards,
    Dengliang Li
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans