Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Retrieving fields from the product entity into the opportunity product entity.

Posted on by 10

Based on a post that I found here, I wrote the below code to automatically look at the product fields and display them on the opportunity product form. 

everything is working fine, except for the product type field which doesn't give me the correct output for some reason. 
The product type field and the license type field are both option set fields with three options each ( identical fields). 
If I put one product that has a product type A, then it displays it on the opportunity product as B
and so on. 
This worked fine when I was working on one option but since we would like to have more options ( I edited the fields to have a third option), it stopped being able to give me the correct output. 
I would really appreciate if someone could tell me what I am doing wrong here. 

//retrieve data based on primary entity id
function retrieveProductFamily() {
//read lookup value

if (Xrm.Page.getAttribute("productid").getValue() != null && Xrm.Page.getAttribute("productid").getValue()[0].id != null) {
var getProduct = Xrm.Page.getAttribute("productid").getValue()[0].id;
getProduct = getProduct.replace(/[{}]/g, "");


//pass entity, fields, we can use expand to get related entity fields
Xrm.WebApi.retrieveRecord("product", getProduct, "?$select=new_testfamily,new_licensetype,new_licenseperiod,new_descriptionenglish,new_descriptionfrench,new_descriptiongerman,new_descriptionitalian,new_descriptionspanish,new_descriptionchinese,new_descriptionportuguese").then(
function success(result) {
if (result != null) {
//set text field
if (result.new_testfamily != null)
Xrm.Page.getAttribute("new_productfamily").setValue(result.new_testfamily);


if (result.new_licensetype != null)
Xrm.Page.getAttribute("new_producttype").setValue(result.new_licensetype);
if(Xrm.Page.getAttribute("new_licenseperiod").getValue()==null)
if (result.new_licenseperiod != null)
Xrm.Page.getAttribute("new_licenseperiod").setValue(result.new_licenseperiod);

if (result.new_descriptionenglish != null)
Xrm.Page.getAttribute("new_descriptionen").setValue(result.new_descriptionenglish);
if (result.new_descriptionfrench != null)
Xrm.Page.getAttribute("new_descriptionfr").setValue(result.new_descriptionfrench);
if (result.new_descriptiongerman != null)
Xrm.Page.getAttribute("new_descriptionde").setValue(result.new_descriptiongerman);
if (result.new_descriptionitalian != null)
Xrm.Page.getAttribute("new_descriptionit").setValue(result.new_descriptionitalian);
if (result.new_descriptionspanish != null)
Xrm.Page.getAttribute("new_descriptiones").setValue(result.new_descriptionspanish);
if (result.new_descriptionchinese != null)
Xrm.Page.getAttribute("new_descriptioncn").setValue(result.new_descriptionchinese);
if (result.new_descriptionportuguese != null)
Xrm.Page.getAttribute("new_descriptionpt").setValue(result.new_descriptionportuguese);


}
},
function(error) {
alert(error.message);

}
);
}
}

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Retrieving fields from the product entity into the opportunity product entity.

    I mean the index value, "Course", "Fixed","Subscription" are labels but make sure their corresponding integer values are same in both the fields.

    5751.value.png

  • Asma G Profile Picture
    Asma G 10 on at
    RE: Retrieving fields from the product entity into the opportunity product entity.

    I am not sure what you mean by index. 

    The first field has 3 options " Course", "Fixed","Subscription" and the second field has the same exact options.

    how would I synch the two fields anyway?

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Retrieving fields from the product entity into the opportunity product entity.

    Hi,

    It seems you have different values (index) in both the entities, make sure both the field should syched in term of their values.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans