web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to retrieve a record from different entity and populate in a form based on selected product?

(0) ShareShare
ReportReport
Posted on by 50

pastedimage1583398672004v4.png

I'm creating this form in Quote Line entity, what I'm trying to do now is I want the Tax Code 2 field is auto-populate based on Existing Product that I chose. The product and its tax code is located in different entity (Product entity).

pastedimage1583398654273v3.png

How do I call the record? I have tried creating another field in Quote Line entity and make 1:N relationship but still, it didn't work out as expected.

I have the same question (0)
  • Suggested answer
    LuHao Profile Picture
    40,892 on at

    Hi Aidel,

    Basically, we will implement it using two OOTB methods: calculated field or workflow.

    Here, I share the steps of the calculated field.

    Background: Product entity has a field "Tax Code".

    pastedimage1583399842276v4.png

    1) Create a calculated field for the Quote Line entity.

    pastedimage1583399551943v1.png

    2) Click Edit to edit its logic. Set its ACTION as productid.new_taxcode. Save.

    pastedimage1583399665929v2.png    pastedimage1583399679784v3.png

    3) Add the calculated field "Tax Code 2" to the Quote Line form. Whenever we select Existing Product and save this record, the field "Tax Code 2" is automatically populated.

    pastedimage1583399927757v5.png

  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi,

    Unfortunately, you have to use a process. Workflow will not be the solution. In fact, you can't update opportunity/quote/order product with workflows. A plugin is a solution.

    Lu Hao, using calculated field, data is calculated as soon as form is loaded. Do you think it won't pose a problem for data consistency?

  • LuHao Profile Picture
    40,892 on at

    Hi Mehdi,

    Yes, calculated fields do get updated when the form loads, which causes the original values to be replaced.

    If the user wants the field "Tax Code 2" to be populated only when the "Existing Product" is changed, then there is no OOTB way, I would recommend creating Javascript as the Onchange event of "Existing Product".

    If the user wants "Tax Code 2" to display the "Tax Code" value of "Existing Product" at all times, then the calculated field is suitable.

  • Aidel Ibrahim Profile Picture
    50 on at

    Just for your information, all products (with taxcode column) I import from excel.

    Now I have two questions:

    1. What if my original Tax Code field from Product is an Option Set. Do I have to change that to calculated field too?

    2. Yes I've been using onchange event too for calculations in quote line (e.g. auto calculate margin% after user key in revenue and margin). Is that possible too to use onchange? If yes then what are the codes that I can use? I'm new to JavaScript.

  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi,

    Your JS code will basically retrieve tax code 2 from the product entity. Then Set the value in your Quote Line. The function will execute when existingProduct is changed.

  • Verified answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, 

    Your code should be something like that: 

    function setProductType(executionContext){
        var formContext = executionContext.getFormContext();
        var existingProduct = formContext.getAttribute('productid').getValue();
        
        var existingProductId = existingProduct[0].id.replace("{","").replace("}",""); 
    
        Xrm.WebApi.retrieveRecord("product", existingProductId, "?$select=new_producttype").then(
            function success(result) {
                formContext.getAttribute('new_producttype').setValue(result.new_producttype);
            },
            function (error) {
                console.log(error.message);
                // handle error conditions
            }
        );
    }

    This code copy an option set value from existing product to an opportunity line. Hope this helps.

  • sharma.sandeep82 Profile Picture
    743 on at

    Hi Aidel,

    I would suggest to use JS for your requirements. We are already using JS for one of our projects for the same kind of requirements. I'll provide the code shortly for your reference.

    Thanks and Regards

    Sandeep

  • Suggested answer
    CRMJetty Profile Picture
    3,514 on at

    Hello Aidel,

    Greetings of the day!

    In regards to your concern, you can use fetchXml query in js ,through fetchXml you will retrieve related entity records in a single query.

    Kindly try the above things on your end and let us know in case of any other concerns, I would be happy to assist you further for the same

    Kind Regards,

    CRMjetty

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

    DynamicsCRM Customer Portal for Wordpress

  • Aidel Ibrahim Profile Picture
    50 on at

    Im facing this error

    Cannot read property 'getFormContext' of undefined

  • Aidel Ibrahim Profile Picture
    50 on at

    Can you brief more? Thank you

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 130 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 117

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans