dynamics crm - How to retrieve all Opportunity Products for the specific Opportunity through c#? -


i have opportunity shown in below image:

opportunity sub items

yesterday, posted question on how create opportunity products (motor products) & dave provided me answer on how achieve this.

now, requirement has been extended delete these existing motor products & add new products.

i'm thinking first retrieving relative motor products opportunity.

for creating opportunity product used below code:

var opportunityproduct = new entity(entitymotorname); opportunityproduct["tmeic_opportunitymotorproductid"] = new entityreference("opportunity", guid("opportunityid")); var opportunityproductid = crmservice.create(opportunityproduct); 

but, i'm stuck here retrieing these motor products. once motor products related opportunity can use below query.

crmservice.delete(entityname,guid); 

note: opportunity has opportunityid no tmeic_opportunitymotorproductid & motor product (opportunityproduct) doesn't have opportunityid has tmeic_opportunitymotorproductid.

only problem how retrieve these motor products?

here's 1 way this:

using microsoft.xrm.sdk; using microsoft.xrm.sdk.query; using microsoft.xrm.tooling.connector; using system; using system.collections.generic; using system.linq;  class app {     private iorganizationservice svc;      public app(iorganizationservice svc)     {         this.svc = svc;     }      public void run()     {         var list = oppproducts(svc, new guid("628cf01a-aed1-e411-80ef-c4346bac7be8"));         deletelist(svc, list);     }      public list<entity> oppproducts(iorganizationservice svc, guid oppid)     {         var query = new queryexpression         {             entityname = "opportunityproduct",             columnset = new columnset("tmeic_opportunitymotorproductid", "opportunityproductid"),             criteria = new filterexpression             {                 filteroperator = logicaloperator.and,                 conditions =                 {                     new conditionexpression                     {                         attributename = "tmeic_opportunitymotorproductid",                         operator = conditionoperator.equal,                         values = { oppid }                     }                    }             }         };          var result = svc.retrievemultiple(query);          return result.entities.tolist();     }      public void deletelist(iorganizationservice svc, list<entity> list)     {         list.foreach(e => svc.delete(e.logicalname, e.id));     } } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -