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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Query / LINQ in Plugin

(0) ShareShare
ReportReport
Posted on by

Hello Experts,

With the help of the valuable responses for my other posts, I was able to read the product properties et al using XrmServiceToolkit in JScript.

    // JQuery to get the product details
    XrmServiceToolkit.Rest.Retrieve(
        pOpProdID,
        "OpportunityProductSet",
        "CreatedOn,OpportunityId,OpportunityProductId,ProductId,OpportunityProduct_Dynamicpropertyinstance/DynamicPropertyId,OpportunityProduct_Dynamicpropertyinstance/DynamicPropertyInstanceid,OpportunityProduct_Dynamicpropertyinstance/ValueDecimal,OpportunityProduct_Dynamicpropertyinstance/ValueDouble,OpportunityProduct_Dynamicpropertyinstance/ValueInteger,OpportunityProduct_Dynamicpropertyinstance/ValueString,opportunity_products/ProductNumber,product_opportunities/CustomerId",
        'lk_opportunityproduct_modifiedonbehalfby,OpportunityProduct_Dynamicpropertyinstance,opportunity_products,product_opportunities',
    function (result) {
        vProjDate = result.CreatedOn;
        vProjectGUID = result.OpportunityId.Id;
        vProjectID = result.OpportunityId.Name;
        vMasterGUID = result.OpportunityProductId;
        vProductId = result.ProductId.Id;
        vProductNumber = result.opportunity_products.ProductNumber;
        vAccID = result.product_opportunities.CustomerId.Id;
        vPropInst = result.OpportunityProduct_Dynamicpropertyinstance;
        // Get the Product Properties and concatenate into a string
        vDynProp = "";
        intPropCount = vPropInst.results.length;
        for (intC = 0; intC < intPropCount; intC++) {
            vDynProp = vDynProp + vPropInst.results[intC].DynamicPropertyId.Name + "-";
            if (vPropInst.results[intC].ValueInteger != null) {
                vDynProp = vDynProp + vPropInst.results[intC].ValueInteger + "|";
            } else if (vPropInst.results[intC].ValueDouble != null) {
                vDynProp = vDynProp + vPropInst.results[intC].ValueDouble + "|";
            } else if (vPropInst.results[intC].ValueDecimal != null) {
                vDynProp = vDynProp + vPropInst.results[intC].ValueDecimal + "|";
            } else if (vDynProp + vPropInst.results[intC].ValueString != null) {
                vDynProp = vDynProp + vPropInst.results[intC].ValueString + "|";
            } else {
                vDynProp = vDynProp + "N/A" + "|";
            }
        }

I am not sure this is the best way, but I am getting the information looking for.
 

This post is to find out instead of form scripting, how I can get this done through a plugin (Query or LINQ). I have tried the obvious ways . Deployed successfully but getting runtime error:

'OpportunityProduct' entity doesn't contain attribute with Name = 'OpportunityProduct_Dynamicpropertyinstance'. 

the LINQ part of my code looks like:

using (myOpportunityContext myContext = new myOpportunityContext(service))
{
	var oppProds = 	from oppProducts in myContext.OpportunityProductSet
			join Prods in myContext.ProductSet								on oppProducts.ProductId.Id equals Prods.Id
			
			where oppProducts.OpportunityId == myOpp.ToEntityReference()
			select new 
			{
	                                       item = Prods.ProductNumber,
                   	                    vPropInst = oppProducts.OpportunityProduct_Dynamicpropertyinstance
                                   		};
//  Some Code here

}


 

Any help appreciated

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    anilambadan Profile Picture
    1,160 on at

    Hi

    The error message suggests 'OpportunityProduct' entity doesn't contain attribute with Name = 'OpportunityProduct_Dynamicpropertyinstance'.  Its a 1:N relation.

    so I think you have to use another join to get the data out. something like

    join p in DynamicPropertyInstanceBases on op.ProductId equals p.RegardingObjectId

    thanks

    Anil

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    The Dynamic Properties in CRM2015 are special in that they have their own set of methods to retrieve and update values.

    You will need to use the RetrieveProductPropertiesRequest:

    See msdn.microsoft.com/.../microsoft.crm.sdk.messages.retrieveproductpropertiesrequest.aspx

    If you want to update them you'll need to use UpdateProductPropertiesRequest:

    msdn.microsoft.com/.../microsoft.crm.sdk.messages.updateproductpropertiesrequest.aspx

    Hope this helps,

    Scott

  • Community Member Profile Picture
    on at

    Thanks Scott. This will also mean that I need to make sure I am using the dll's from the 2015 SDK as Product Properties is something new in CRM 2015. Last day I struggled a lot with deployment of a plugin targeting .net 4.5.2 and the dlls version 7.x (2015). I was getting the "unable to find assembly debug/bin/<pugin name>.dll" error. I have made sure that:

    1) the target framework of the plugin as well as the workflow projects are 4.5.2

    2) edited the crmpackage.csprj to change v4.5 to v4.5.2 (as mentioned in one of your previous replies in the community on a similar error)

    3) made sure all the references are using the latest dlls (form 2015 SDK)

    The project is bulding successfully (and the dlls are getting created under bin folder) but getting the error "Unable to Deploy.. Cannot find .dll".

    Sorry for the detour, but I am sure that once I update the references with latest dlls for "RetrieveProductPropertiesRequest", I will get stuck with this error.

    Regards

  • ScottDurow Profile Picture
    21 on at

    Those steps you describe are all that is needed to get the crm2015 assemblies working-I've been doing it for ages!

  • ScottDurow Profile Picture
    21 on at

    How did you get on?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans