Bhubaneswar, Odisha, India
+91-8328865778
support@logyscal.com

Navigation Property for Lookup Field in Xrm.WebAPI Create – How to use

Navigation Property for Lookup Field in Xrm.WebAPI Create – How to use

In this below blog, you will come to know how to use assign value to single lookup field and polymorphic lookup field while passing data in Xrm.WebAPI request in Javascript for Dataverse Power Apps

Single Entity Lookup

If you want to assign value of a lookup field which is associated with a single entity then use below format.

“<SchemaName_of_LookupField>@odata.bind”:”/<setnameofentity>(<id_of_parent_record>)”

Example : “sbi_BankAccount@odata.bind”: “/sbi_sbibankaccounts(“+currentBankAccountRecId+”)”

Schema Name can ebe copied from Solution => Table -> Field -> Property -> Schema Name

NOTE :

Entity Set name can be copied using Advanced Tool from Power Apps Solution Entity Component. Navigate to your solution, select the entity from solution, click Tool and choose Copy Set Name.

Polymorphic Entity Lookup

If you want to assign polymorphic lookup field value like Customer datatype then you have to append target entity logical name with scena name of the column as given below.

“<SchemaName_of_LookupField>_<targetentitylogicalname>@odata.bind”:”/<setnameoftargetentity>(<id_of_parent_record>)”

Example : “sbi_Customer_contact@odata.bind”: “/contacts(<contactid>)”

sbi_Customer_account@odata.bind”: “/accounts(<contactid>)”

FINAL CODE with Both Case

Here I have given a sample code with both lookup type. In this code Bank Account is a Single entity lookup but Customer is a polymorphic lookup. For Power Automate also when you assign you have to assign in correct way.

function createCreditCard(formContext)
{
    var currentBankAccountRecId= formContext.data.entity.getId().replace("{","").replace("}","");
    var customer = formContext.getAttribute("sbi_customer").getValue();  
    var customerid = customer[0].id.replace("{","").replace("}","");
    
    var data =
    {
        "sbi_Customer_contact@odata.bind": "/contacts("+customerid+")",
        "sbi_cardtype":918820001,
        "sbi_BankAccount@odata.bind": "/sbi_sbibankaccounts("+currentBankAccountRecId+")",
        "sbi_maximumlimit": 150000
    }

    // create account record
    Xrm.WebApi.createRecord("sbi_sbicard", data).then(
    function success(result) {
        alert("Credit card is created with ID: " + result.id);
        // perform operations on record creation
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
    );
}

In Power Automate, you have to assign corrctly as given below screenshot.

You can enroll now !We are giving 30% discount on our Internship Program

Don’t miss the chance to participate in the upcoming Internship Program which will be done using Microsoft Dot Net Web Development Full Stack Technology. The new batch will be starting from May 20, 2024.  We will have most experienced trainers for you to successfully complete the internship with live project experience.

Why to choose Our Internship Program?

Industry-Relevant Projects
Tailored Assignments: We offer projects that align with your academic background and career aspirations.
Real-World Challenges: Tackle industry-specific problems and contribute to meaningful projects that make a difference.

Professional Mentorship
Guidance from Experts: Benefit from one-on-one mentorship from seasoned professionals in your field.
Career Development Workshops: Participate in workshops that focus on resume building, interview skills, and career planning.

Networking Opportunities
Connect with Industry Leaders: Build relationships with professionals and expand your professional network.
Peer Interaction: Collaborate with fellow interns and exchange ideas, fostering a supportive and collaborative environment.

Skill Enhancement
Hands-On Experience: Gain practical skills and learn new technologies through project-based learning.
Soft Skills Development: Enhance communication, teamwork, and problem-solving skills essential for career success.

Free Demo Class Available