Produced by Araxis Merge on 2/1/2017 2:56:35 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\CS\GeneralProgramming\Queries | RetrieveMultipleConditionOperatorsQE.cs | Tue Dec 20 19:51:46 2016 UTC |
| 2 | Wed Feb 1 19:56:35 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 659 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 2 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 3 | // | |||||
| 4 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 5 | // | |||||
| 6 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 7 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 8 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 9 | // | |||||
| 10 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 11 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 12 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 13 | // PARTIC ULAR PURPO SE. | |||||
| 14 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 15 | ||||||
| 16 | //<snippet RetrieveMu ltipleCond itionOpera torsQE> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Collect ions.Gener ic; | |||||
| 20 | ||||||
| 21 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 22 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 23 | using Micr osoft.Xrm. Sdk; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | ||||||
| 27 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 28 | { | |||||
| 29 | /// <s ummary> | |||||
| 30 | /// De monstrates how to do use retri eve multip le conditi on operato rs for all | |||||
| 31 | /// qu ery types. </summary> | |||||
| 32 | /// <r emarks> | |||||
| 33 | /// At run-time, you will be given t he option to delete all the | |||||
| 34 | /// da tabase rec ords creat ed by this program.< /remarks> | |||||
| 35 | public class Ret rieveMulti pleConditi onOperator sQE | |||||
| 36 | { | |||||
| 37 | #r egion Clas s Level Me mbers | |||||
| 38 | ||||||
| 39 | pr ivate Guid _accountI d; | |||||
| 40 | pr ivate Guid _productI d; | |||||
| 41 | pr ivate Guid _priceLev elId; | |||||
| 42 | pr ivate Guid _productP riceId; | |||||
| 43 | pr ivate Guid _unitGrou pId; | |||||
| 44 | pr ivate List <Guid> _co ntactIdLis t = new Li st<Guid>() ; | |||||
| 45 | pr ivate List <Guid> _op portunityI dList = ne w List<Gui d>(); | |||||
| 46 | pr ivate List <Guid> _or derIdList = new List <Guid>(); | |||||
| 47 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 48 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 49 | ||||||
| 50 | #e ndregion C lass Level Members | |||||
| 51 | ||||||
| 52 | #r egion How To Sample Code | |||||
| 53 | // / <summary > | |||||
| 54 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, various | |||||
| 55 | // / QueryExp ressions a re perform ed that de monstrate the use of special | |||||
| 56 | // / conditio n operator s. | |||||
| 57 | // / </summar y> | |||||
| 58 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 59 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 60 | // / created entities.< /param> | |||||
| 61 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 62 | { | |||||
| 63 | try | |||||
| 64 | { | |||||
| 65 | ||||||
| 66 | // C onnect to the Organi zation ser vice. | |||||
| 67 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 68 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,server Config.Cre dentials, serverConf ig.DeviceC redentials )) | |||||
| 69 | { | |||||
| 70 | // This st atement is required to enable early-boun d type sup port. | |||||
| 71 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 72 | ||||||
| 73 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 74 | ||||||
| 75 | CreateRequ iredRecord s(); | |||||
| 76 | ||||||
| 77 | #region SQ L Query Tr anslated t o QueryExp ression | |||||
| 78 | //<snippet RetrieveMu ltipleCond itionOpera torsQE1> | |||||
| 79 | // Build t he followi ng SQL que ry using Q ueryExpres sion: | |||||
| 80 | // | |||||
| 81 | // SELECT c ontact.ful lname, con tact.addre ss1_teleph one1 | |||||
| 82 | // FROM con tact | |||||
| 83 | // LEFT OUTER JOIN acco unt | |||||
| 84 | // ON contact.p arentcusto merid = ac count.acco untid | |||||
| 85 | // AN D | |||||
| 86 | // ac count.name = 'Litwar e, Inc.' | |||||
| 87 | // WHERE (c ontact.add ress1_stat eorprovinc e = 'WA' | |||||
| 88 | // AND | |||||
| 89 | // contact.ad dress1_cit y in ('Red mond', 'Be llevue', ' Kirkland', 'Seattle' ) | |||||
| 90 | // AND | |||||
| 91 | // contact.ad dress1_tel ephone1 li ke '(206)% ' | |||||
| 92 | // OR | |||||
| 93 | // contact.ad dress1_tel ephone1 li ke '(425)% ' | |||||
| 94 | // AND | |||||
| 95 | // DATEDIFF(D AY, contac t.createdo n, GETDATE ()) > 0 | |||||
| 96 | // AND | |||||
| 97 | // DATEDIFF(D AY, contac t.createdo n, GETDATE ()) < 30 | |||||
| 98 | // AND | |||||
| 99 | // contact.em ailaddress 1 Not NULL | |||||
| 100 | // ) | |||||
| 101 | ||||||
| 102 | QueryExpre ssion quer y = new Qu eryExpress ion() | |||||
| 103 | { | |||||
| 104 | Distin ct = false , | |||||
| 105 | Entity Name = Con tact.Entit yLogicalNa me, | |||||
| 106 | Column Set = new ColumnSet( "fullname" , "address 1_telephon e1"), | |||||
| 107 | LinkEn tities = | |||||
| 108 | { | |||||
| 109 | ne w LinkEnti ty | |||||
| 110 | { | |||||
| 111 | JoinOper ator = Joi nOperator. LeftOuter, | |||||
| 112 | LinkFrom AttributeN ame = "par entcustome rid", | |||||
| 113 | LinkFrom EntityName = Contact .EntityLog icalName, | |||||
| 114 | LinkToAt tributeNam e = "accou ntid", | |||||
| 115 | LinkToEn tityName = Account.E ntityLogic alName, | |||||
| 116 | LinkCrit eria = | |||||
| 117 | { | |||||
| 118 | Cond itions = | |||||
| 119 | { | |||||
| 120 | new Condit ionExpress ion("name" , Conditio nOperator. Equal, "Li tware, Inc .") | |||||
| 121 | } | |||||
| 122 | } | |||||
| 123 | } | |||||
| 124 | }, | |||||
| 125 | Criter ia = | |||||
| 126 | { | |||||
| 127 | Fi lters = | |||||
| 128 | { | |||||
| 129 | new Filt erExpressi on | |||||
| 130 | { | |||||
| 131 | Filt erOperator = Logical Operator.A nd, | |||||
| 132 | Cond itions = | |||||
| 133 | { | |||||
| 134 | new Condit ionExpress ion("addre ss1_stateo rprovince" , Conditio nOperator. Equal, "WA "), | |||||
| 135 | new Condit ionExpress ion("addre ss1_city", Condition Operator.I n, new Str ing[] {"Re dmond", "B ellevue" , "Kirkland ", "Seattl e"}), | |||||
| 136 | new Condit ionExpress ion("creat edon", Con ditionOper ator.LastX Days, 30), | |||||
| 137 | new Condit ionExpress ion("email address1", Condition Operator.N otNull) | |||||
| 138 | }, | |||||
| 139 | }, | |||||
| 140 | new Filt erExpressi on | |||||
| 141 | { | |||||
| 142 | Filt erOperator = Logical Operator.O r, | |||||
| 143 | Cond itions = | |||||
| 144 | { | |||||
| 145 | new Condit ionExpress ion("addre ss1_teleph one1", Con ditionOper ator.Like, "(206)%") , | |||||
| 146 | new Condit ionExpress ion("addre ss1_teleph one1", Con ditionOper ator.Like, "(425)%") | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | } | |||||
| 150 | } | |||||
| 151 | }; | |||||
| 152 | ||||||
| 153 | DataCollec tion<Entit y> entityC ollection = _service .RetrieveM ultiple(qu ery).Entit ies; | |||||
| 154 | ||||||
| 155 | // Display the resul ts. | |||||
| 156 | Console.Wr iteLine("L ist all co ntacts mat ching spec ified para meters"); | |||||
| 157 | Console.Wr iteLine("= ========== ========== ========== ========== ======"); | |||||
| 158 | foreach (C ontact con tact in en tityCollec tion) | |||||
| 159 | { | |||||
| 160 | Consol e.WriteLin e("Contact ID: {0}", contact.I d); | |||||
| 161 | Consol e.WriteLin e("Contact Name: {0} ", contact .FullName) ; | |||||
| 162 | Consol e.WriteLin e("Contact Phone: {0 }", contac t.Address1 _Telephone 1); | |||||
| 163 | } | |||||
| 164 | Console.Wr iteLine("< End of Lis ting>"); | |||||
| 165 | Console.Wr iteLine(); | |||||
| 166 | //</snippe tRetrieveM ultipleCon ditionOper atorsQE1> | |||||
| 167 | #endregion | |||||
| 168 | ||||||
| 169 | #region Fi nd all ord ers fulfil led in the last fisc al period | |||||
| 170 | //<snippet RetrieveMu ltipleCond itionOpera torsQE2> | |||||
| 171 | query = ne w QueryExp ression() | |||||
| 172 | { | |||||
| 173 | Entity Name = Sal esOrder.En tityLogica lName, | |||||
| 174 | Column Set = new ColumnSet( "name"), | |||||
| 175 | Criter ia = | |||||
| 176 | { | |||||
| 177 | Co nditions = | |||||
| 178 | { | |||||
| 179 | new Cond itionExpre ssion ("da tefulfille d", Condit ionOperato r.LastFisc alPeriod) | |||||
| 180 | } | |||||
| 181 | } | |||||
| 182 | }; | |||||
| 183 | ||||||
| 184 | entityColl ection = _ service.Re trieveMult iple(query ).Entities ; | |||||
| 185 | ||||||
| 186 | // Display the resul ts. | |||||
| 187 | Console.Wr iteLine("L ist all or ders fulfi lled in th e last fis cal period "); | |||||
| 188 | Console.Wr iteLine("= ========== ========== ========== ========== ========== "); | |||||
| 189 | foreach (S alesOrder order in e ntityColle ction) | |||||
| 190 | { | |||||
| 191 | Consol e.WriteLin e("Order I D: {0}", o rder.Id); | |||||
| 192 | Consol e.WriteLin e("Order N ame: {0}", order.Nam e); | |||||
| 193 | } | |||||
| 194 | Console.Wr iteLine("< End of Lis ting>"); | |||||
| 195 | Console.Wr iteLine(); | |||||
| 196 | //</snippe tRetrieveM ultipleCon ditionOper atorsQE2> | |||||
| 197 | #endregion | |||||
| 198 | ||||||
| 199 | #region Fi nd all Opp ortunities with esti mated clos e date in next 3 fis cal years | |||||
| 200 | //<snippet RetrieveMu ltipleCond itionOpera torsQE3> | |||||
| 201 | query = ne w QueryExp ression() | |||||
| 202 | { | |||||
| 203 | Entity Name = Opp ortunity.E ntityLogic alName, | |||||
| 204 | Column Set = new ColumnSet( "name"), | |||||
| 205 | Criter ia = | |||||
| 206 | { | |||||
| 207 | Co nditions = | |||||
| 208 | { | |||||
| 209 | new Cond itionExpre ssion ("es timatedclo sedate", C onditionOp erator.Nex tXFiscalYe ars, 3) | |||||
| 210 | } | |||||
| 211 | } | |||||
| 212 | }; | |||||
| 213 | ||||||
| 214 | entityColl ection = _ service.Re trieveMult iple(query ).Entities ; | |||||
| 215 | ||||||
| 216 | // Display the resul ts. | |||||
| 217 | Console.Wr iteLine("L ist all op portunitie s with est imated clo se date in the next 3 fiscal y ears"); | |||||
| 218 | Console.Wr iteLine("= ========== ========== ========== ========== ========== ========== ========== ===="); | |||||
| 219 | foreach (O pportunity opportuni ty in enti tyCollecti on) | |||||
| 220 | { | |||||
| 221 | Consol e.WriteLin e("Opportu nity ID: { 0}", oppor tunity.Id) ; | |||||
| 222 | Consol e.WriteLin e("Opportu nity: {0}" , opportun ity.Name); | |||||
| 223 | } | |||||
| 224 | Console.Wr iteLine("< End of Lis ting>"); | |||||
| 225 | Console.Wr iteLine(); | |||||
| 226 | //</snippe tRetrieveM ultipleCon ditionOper atorsQE3> | |||||
| 227 | #endregion | |||||
| 228 | ||||||
| 229 | #region Fi nd all Ord ers fulfil led in fis cal year 2 008 | |||||
| 230 | //<snippet RetrieveMu ltipleCond itionOpera torsQE4> | |||||
| 231 | query = ne w QueryExp ression() | |||||
| 232 | { | |||||
| 233 | Entity Name = Sal esOrder.En tityLogica lName, | |||||
| 234 | Column Set = new ColumnSet( "name"), | |||||
| 235 | Criter ia = | |||||
| 236 | { | |||||
| 237 | Co nditions = | |||||
| 238 | { | |||||
| 239 | new Cond itionExpre ssion ("da tefulfille d", Condit ionOperato r.InFiscal Year, 2008 ) | |||||
| 240 | } | |||||
| 241 | } | |||||
| 242 | }; | |||||
| 243 | ||||||
| 244 | entityColl ection = _ service.Re trieveMult iple(query ).Entities ; | |||||
| 245 | ||||||
| 246 | // Display the resul ts. | |||||
| 247 | Console.Wr iteLine("L ist all or ders fulfi lled in fi scal year 2008"); | |||||
| 248 | Console.Wr iteLine("= ========== ========== ========== ========== ===="); | |||||
| 249 | foreach (S alesOrder order in e ntityColle ction) | |||||
| 250 | { | |||||
| 251 | Consol e.WriteLin e("Order I D: {0}", o rder.Id); | |||||
| 252 | Consol e.WriteLin e("Order N ame: {0}", order.Nam e); | |||||
| 253 | } | |||||
| 254 | Console.Wr iteLine("< End of Lis ting>"); | |||||
| 255 | Console.Wr iteLine(); | |||||
| 256 | //</snippe tRetrieveM ultipleCon ditionOper atorsQE4> | |||||
| 257 | #endregion | |||||
| 258 | ||||||
| 259 | #region Fi nd all Ord ers fulfil led in per iod 3 of a ny fiscal year | |||||
| 260 | //<snippet RetrieveMu ltipleCond itionOpera torsQE5> | |||||
| 261 | query = ne w QueryExp ression() | |||||
| 262 | { | |||||
| 263 | Entity Name = Sal esOrder.En tityLogica lName, | |||||
| 264 | Column Set = new ColumnSet( "name"), | |||||
| 265 | Criter ia = | |||||
| 266 | { | |||||
| 267 | Co nditions = | |||||
| 268 | { | |||||
| 269 | new Cond itionExpre ssion ("da tefulfille d", Condit ionOperato r.InFiscal Period, 3) | |||||
| 270 | } | |||||
| 271 | } | |||||
| 272 | }; | |||||
| 273 | ||||||
| 274 | entityColl ection = _ service.Re trieveMult iple(query ).Entities ; | |||||
| 275 | ||||||
| 276 | // Display the resul ts. | |||||
| 277 | Console.Wr iteLine("L ist all or ders fulfi lled in pe riod 3 of any fiscal year"); | |||||
| 278 | Console.Wr iteLine("= ========== ========== ========== ========== ========== ====="); | |||||
| 279 | foreach (S alesOrder order in e ntityColle ction) | |||||
| 280 | { | |||||
| 281 | Consol e.WriteLin e("Order I D: {0}", o rder.Id); | |||||
| 282 | Consol e.WriteLin e("Order N ame: {0}", order.Nam e); | |||||
| 283 | } | |||||
| 284 | Console.Wr iteLine("< End of Lis ting>"); | |||||
| 285 | Console.Wr iteLine(); | |||||
| 286 | //</snippe tRetrieveM ultipleCon ditionOper atorsQE5> | |||||
| 287 | #endregion | |||||
| 288 | ||||||
| 289 | #region Fi nd all Ord ers fulfil led in per iod 3 of f iscal year 2008 | |||||
| 290 | //<snippet RetrieveMu ltipleCond itionOpera torsQE6> | |||||
| 291 | query = ne w QueryExp ression() | |||||
| 292 | { | |||||
| 293 | Entity Name = Sal esOrder.En tityLogica lName, | |||||
| 294 | Column Set = new ColumnSet( "name"), | |||||
| 295 | Criter ia = | |||||
| 296 | { | |||||
| 297 | Co nditions = | |||||
| 298 | { | |||||
| 299 | new Cond itionExpre ssion ("da tefulfille d", Condit ionOperato r.InFiscal PeriodAndY ear, new i nt[] {3, 2 008}) | |||||
| 300 | } | |||||
| 301 | } | |||||
| 302 | }; | |||||
| 303 | ||||||
| 304 | entityColl ection = _ service.Re trieveMult iple(query ).Entities ; | |||||
| 305 | ||||||
| 306 | // Display the resul ts. | |||||
| 307 | Console.Wr iteLine("L ist all or ders fulfi lled in pe riod 3 of fiscal yea r 2008"); | |||||
| 308 | Console.Wr iteLine("= ========== ========== ========== ========== ========== ======"); | |||||
| 309 | foreach (S alesOrder order in e ntityColle ction) | |||||
| 310 | { | |||||
| 311 | Consol e.WriteLin e("Order I D: {0}", o rder.Id); | |||||
| 312 | Consol e.WriteLin e("Order N ame: {0}", order.Nam e); | |||||
| 313 | } | |||||
| 314 | Console.Wr iteLine("< End of Lis ting>"); | |||||
| 315 | Console.Wr iteLine(); | |||||
| 316 | //</snippe tRetrieveM ultipleCon ditionOper atorsQE6> | |||||
| 317 | #endregion | |||||
| 318 | ||||||
| 319 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 320 | } | |||||
| 321 | ||||||
| 322 | } | |||||
| 323 | ||||||
| 324 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 325 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 326 | { | |||||
| 327 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 328 | thro w; | |||||
| 329 | } | |||||
| 330 | } | |||||
| 331 | ||||||
| 332 | // / <summary > | |||||
| 333 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 334 | // / </summar y> | |||||
| 335 | pu blic void CreateRequ iredRecord s() | |||||
| 336 | { | |||||
| 337 | // Creat e a unit g roup. | |||||
| 338 | UoMSched ule unitGr oup = new UoMSchedul e | |||||
| 339 | { | |||||
| 340 | Name = "Exampl e Unit Gro up", | |||||
| 341 | Base UoMName = "Example P rimary Uni t" | |||||
| 342 | }; | |||||
| 343 | _unitGro upId = _se rvice.Crea te(unitGro up); | |||||
| 344 | ||||||
| 345 | // Retri eve the un it. | |||||
| 346 | QueryExp ression un itQuery = new QueryE xpression( ) | |||||
| 347 | { | |||||
| 348 | Enti tyName = U oM.EntityL ogicalName , | |||||
| 349 | Colu mnSet = ne w ColumnSe t("uomid", "name"), | |||||
| 350 | Crit eria = | |||||
| 351 | { | |||||
| 352 | Conditions = | |||||
| 353 | { | |||||
| 354 | new Co nditionExp ression (" uomschedul eid", Cond itionOpera tor.Equal, _unitGrou pId) | |||||
| 355 | } | |||||
| 356 | }, | |||||
| 357 | Page Info = new PagingInf o | |||||
| 358 | { | |||||
| 359 | PageNumber = 1, | |||||
| 360 | Count = 1 | |||||
| 361 | } | |||||
| 362 | }; | |||||
| 363 | UoM unit = (UoM)_s ervice.Ret rieveMulti ple(unitQu ery).Entit ies[0]; | |||||
| 364 | ||||||
| 365 | // Creat e an accou nt. | |||||
| 366 | Account account = new Accoun t | |||||
| 367 | { | |||||
| 368 | Name = "Litwar e, Inc.", | |||||
| 369 | Addr ess1_State OrProvince = "Colora do" | |||||
| 370 | }; | |||||
| 371 | _account Id = (_ser vice.Creat e(account) ); | |||||
| 372 | ||||||
| 373 | // Creat e the 2 co ntacts. | |||||
| 374 | Contact contact = new Contac t() | |||||
| 375 | { | |||||
| 376 | Firs tName = "B en", | |||||
| 377 | Last Name = "An drews", | |||||
| 378 | EMai lAddress1 = "sample@ example.co m", | |||||
| 379 | Addr ess1_City = "Redmond ", | |||||
| 380 | Addr ess1_State OrProvince = "WA", | |||||
| 381 | Addr ess1_Telep hone1 = "( 206)555-55 55", | |||||
| 382 | Pare ntCustomer Id = new E ntityRefer ence | |||||
| 383 | { | |||||
| 384 | Id = _acco untId, | |||||
| 385 | LogicalNam e = accoun t.LogicalN ame | |||||
| 386 | } | |||||
| 387 | }; | |||||
| 388 | _contact IdList.Add (_service. Create(con tact)); | |||||
| 389 | ||||||
| 390 | contact = new Cont act() | |||||
| 391 | { | |||||
| 392 | Firs tName = "C olin", | |||||
| 393 | Last Name = "Wi lcox", | |||||
| 394 | EMai lAddress1 = "sample@ example.co m", | |||||
| 395 | Addr ess1_City = "Bellevu e", | |||||
| 396 | Addr ess1_State OrProvince = "WA", | |||||
| 397 | Addr ess1_Telep hone1 = "( 425)555-55 55", | |||||
| 398 | Pare ntCustomer Id = new E ntityRefer ence | |||||
| 399 | { | |||||
| 400 | Id = _acco untId, | |||||
| 401 | LogicalNam e = accoun t.LogicalN ame | |||||
| 402 | } | |||||
| 403 | }; | |||||
| 404 | _contact IdList.Add (_service. Create(con tact)); | |||||
| 405 | ||||||
| 406 | // Creat e pricing and produc t objects. | |||||
| 407 | PriceLev el priceLe vel = new PriceLevel () | |||||
| 408 | { | |||||
| 409 | Name = "Faux P rice List" | |||||
| 410 | }; | |||||
| 411 | _priceLe velId = _s ervice.Cre ate(priceL evel); | |||||
| 412 | ||||||
| 413 | Product product = new Produc t() | |||||
| 414 | { | |||||
| 415 | Prod uctNumber = "1", | |||||
| 416 | Quan tityDecima l = 4, | |||||
| 417 | Name = "Faux P roduct", | |||||
| 418 | Defa ultUoMId = new Entit yReference | |||||
| 419 | { | |||||
| 420 | Id = unit. Id, | |||||
| 421 | LogicalNam e = UoM.En tityLogica lName | |||||
| 422 | }, | |||||
| 423 | Defa ultUoMSche duleId = n ew EntityR eference | |||||
| 424 | { | |||||
| 425 | Id = _unit GroupId, | |||||
| 426 | LogicalNam e = UoMSch edule.Enti tyLogicalN ame | |||||
| 427 | } | |||||
| 428 | }; | |||||
| 429 | _product Id = _serv ice.Create (product); | |||||
| 430 | ||||||
| 431 | ProductP riceLevel productPri ce = new P roductPric eLevel() | |||||
| 432 | { | |||||
| 433 | Pric eLevelId = new Entit yReference () | |||||
| 434 | { | |||||
| 435 | Id = _pric eLevelId, | |||||
| 436 | LogicalNam e = PriceL evel.Entit yLogicalNa me | |||||
| 437 | }, | |||||
| 438 | Prod uctId = ne w EntityRe ference() | |||||
| 439 | { | |||||
| 440 | Id = _prod uctId, | |||||
| 441 | LogicalNam e = Produc t.EntityLo gicalName | |||||
| 442 | }, | |||||
| 443 | UoMI d = new En tityRefere nce | |||||
| 444 | { | |||||
| 445 | Id = unit. Id, | |||||
| 446 | LogicalNam e = UoM.En tityLogica lName | |||||
| 447 | }, | |||||
| 448 | Amou nt = new M oney(20) | |||||
| 449 | }; | |||||
| 450 | _product PriceId = _service.C reate(prod uctPrice); | |||||
| 451 | ||||||
| 452 | // Creat e 3 orders . | |||||
| 453 | SalesOrd er order = new Sales Order() | |||||
| 454 | { | |||||
| 455 | Name = "Faux O rder", | |||||
| 456 | Date Fulfilled = new Date Time(2010, 8, 1), | |||||
| 457 | Pric eLevelId = new Entit yReference | |||||
| 458 | { | |||||
| 459 | Id = _pric eLevelId, | |||||
| 460 | LogicalNam e = PriceL evel.Entit yLogicalNa me | |||||
| 461 | }, | |||||
| 462 | Cust omerId = n ew EntityR eference | |||||
| 463 | { | |||||
| 464 | Id = _acco untId, | |||||
| 465 | LogicalNam e = accoun t.LogicalN ame | |||||
| 466 | } | |||||
| 467 | }; | |||||
| 468 | _orderId List.Add(_ service.Cr eate(order )); | |||||
| 469 | ||||||
| 470 | order = new SalesO rder() | |||||
| 471 | { | |||||
| 472 | Name = "Old Fa ux Order", | |||||
| 473 | Date Fulfilled = new Date Time(2010, 4, 1), | |||||
| 474 | Pric eLevelId = new Entit yReference | |||||
| 475 | { | |||||
| 476 | Id = _pric eLevelId, | |||||
| 477 | LogicalNam e = PriceL evel.Entit yLogicalNa me | |||||
| 478 | }, | |||||
| 479 | Cust omerId = n ew EntityR eference | |||||
| 480 | { | |||||
| 481 | Id = _acco untId, | |||||
| 482 | LogicalNam e = accoun t.LogicalN ame | |||||
| 483 | } | |||||
| 484 | }; | |||||
| 485 | _orderId List.Add(_ service.Cr eate(order )); | |||||
| 486 | ||||||
| 487 | order = new SalesO rder() | |||||
| 488 | { | |||||
| 489 | Name = "Oldest Faux Orde r", | |||||
| 490 | Date Fulfilled = new Date Time(2008, 8, 1), | |||||
| 491 | Pric eLevelId = new Entit yReference | |||||
| 492 | { | |||||
| 493 | Id = _pric eLevelId, | |||||
| 494 | LogicalNam e = PriceL evel.Entit yLogicalNa me | |||||
| 495 | }, | |||||
| 496 | Cust omerId = n ew EntityR eference | |||||
| 497 | { | |||||
| 498 | Id = _acco untId, | |||||
| 499 | LogicalNam e = accoun t.LogicalN ame | |||||
| 500 | } | |||||
| 501 | }; | |||||
| 502 | _orderId List.Add(_ service.Cr eate(order )); | |||||
| 503 | ||||||
| 504 | // Creat e 2 opport unities. | |||||
| 505 | Opportun ity opport unity = ne w Opportun ity() | |||||
| 506 | { | |||||
| 507 | Name = "Litwar e, Inc. Op portunity 1", | |||||
| 508 | Esti matedClose Date = new DateTime( 2011, 1, 1 ), | |||||
| 509 | Cust omerId = n ew EntityR eference | |||||
| 510 | { | |||||
| 511 | Id = _acco untId, | |||||
| 512 | LogicalNam e = accoun t.LogicalN ame | |||||
| 513 | } | |||||
| 514 | }; | |||||
| 515 | _opportu nityIdList .Add(_serv ice.Create (opportuni ty)); | |||||
| 516 | ||||||
| 517 | opportun ity = new Opportunit y() | |||||
| 518 | { | |||||
| 519 | Name = "Litwar e, Inc. Op portunity 2", | |||||
| 520 | Esti matedClose Date = new DateTime( 2020, 1, 1 ), | |||||
| 521 | Cust omerId = n ew EntityR eference | |||||
| 522 | { | |||||
| 523 | Id = _acco untId, | |||||
| 524 | LogicalNam e = accoun t.LogicalN ame | |||||
| 525 | } | |||||
| 526 | }; | |||||
| 527 | _opportu nityIdList .Add(_serv ice.Create (opportuni ty)); | |||||
| 528 | } | |||||
| 529 | ||||||
| 530 | // / <summary > | |||||
| 531 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 532 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 533 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 534 | // / </summar y> | |||||
| 535 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 536 | { | |||||
| 537 | bool toB eDeleted = true; | |||||
| 538 | ||||||
| 539 | if (prom pt) | |||||
| 540 | { | |||||
| 541 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 542 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 543 | Stri ng answer = Console. ReadLine() ; | |||||
| 544 | if ( answer.Sta rtsWith("y ") || | |||||
| 545 | answer.Sta rtsWith("Y ") || | |||||
| 546 | answer == String.Emp ty) | |||||
| 547 | { | |||||
| 548 | toBeDelete d = true; | |||||
| 549 | } | |||||
| 550 | else | |||||
| 551 | { | |||||
| 552 | toBeDelete d = false; | |||||
| 553 | } | |||||
| 554 | } | |||||
| 555 | ||||||
| 556 | if (toBe Deleted) | |||||
| 557 | { | |||||
| 558 | // D elete all records cr eated in t his sample . | |||||
| 559 | fore ach (Guid contactId in _contac tIdList) | |||||
| 560 | { | |||||
| 561 | _service.D elete(Cont act.Entity LogicalNam e, contact Id); | |||||
| 562 | } | |||||
| 563 | ||||||
| 564 | fore ach (Guid opportunit yId in _op portunityI dList) | |||||
| 565 | { | |||||
| 566 | _service.D elete(Oppo rtunity.En tityLogica lName, opp ortunityId ); | |||||
| 567 | } | |||||
| 568 | ||||||
| 569 | fore ach (Guid orderId in _orderIdL ist) | |||||
| 570 | { | |||||
| 571 | _service.D elete(Sale sOrder.Ent ityLogical Name, orde rId); | |||||
| 572 | } | |||||
| 573 | ||||||
| 574 | _ser vice.Delet e(Account. EntityLogi calName, _ accountId) ; | |||||
| 575 | ||||||
| 576 | _ser vice.Delet e(Product. EntityLogi calName, _ productId) ; | |||||
| 577 | ||||||
| 578 | _ser vice.Delet e(PriceLev el.EntityL ogicalName , _priceLe velId); | |||||
| 579 | ||||||
| 580 | _ser vice.Delet e(UoMSched ule.Entity LogicalNam e, _unitGr oupId); | |||||
| 581 | ||||||
| 582 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 583 | } | |||||
| 584 | } | |||||
| 585 | ||||||
| 586 | #e ndregion H ow To Samp le Code | |||||
| 587 | ||||||
| 588 | #r egion Main method | |||||
| 589 | ||||||
| 590 | // / <summary > | |||||
| 591 | // / Standard Main() me thod used by most SD K samples. | |||||
| 592 | // / </summar y> | |||||
| 593 | // / <param n ame="args" ></param> | |||||
| 594 | st atic publi c void Mai n(string[] args) | |||||
| 595 | { | |||||
| 596 | try | |||||
| 597 | { | |||||
| 598 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 599 | // c redentials from the user. | |||||
| 600 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 601 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 602 | ||||||
| 603 | Retr ieveMultip leConditio nOperators QE app = n ew Retriev eMultipleC onditionOp eratorsQE( ); | |||||
| 604 | app. Run(config , true); | |||||
| 605 | } | |||||
| 606 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 607 | { | |||||
| 608 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 609 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 610 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 611 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 612 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 613 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 614 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 615 | } | |||||
| 616 | catch (S ystem.Time outExcepti on ex) | |||||
| 617 | { | |||||
| 618 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 619 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 620 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 621 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 622 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 623 | } | |||||
| 624 | catch (S ystem.Exce ption ex) | |||||
| 625 | { | |||||
| 626 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 627 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 628 | ||||||
| 629 | // D isplay the details o f the inne r exceptio n. | |||||
| 630 | if ( ex.InnerEx ception != null) | |||||
| 631 | { | |||||
| 632 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 633 | ||||||
| 634 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 635 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 636 | if (fe != null) | |||||
| 637 | { | |||||
| 638 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 639 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 640 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 641 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 642 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 643 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 644 | } | |||||
| 645 | } | |||||
| 646 | } | |||||
| 647 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 648 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 649 | ||||||
| 650 | finally | |||||
| 651 | { | |||||
| 652 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 653 | Cons ole.ReadLi ne(); | |||||
| 654 | } | |||||
| 655 | } | |||||
| 656 | #e ndregion M ain method | |||||
| 657 | } | |||||
| 658 | } | |||||
| 659 | //</snippe tRetrieveM ultipleCon ditionOper atorsQE> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.