Produced by Araxis Merge on 2/1/2017 2:56:23 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\BusinessDataModel\BusinessManagement | FulfillSalesOrder.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:23 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 287 |
| 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 FulfillSal esOrder> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Linq; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 21 | using Micr osoft.Xrm. Sdk; | |||||
| 22 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 23 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | ||||||
| 27 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 28 | { | |||||
| 29 | /// <s ummary> | |||||
| 30 | /// Th is sample creates a SalesOrder record an d demonstr ates how t o use the | |||||
| 31 | /// Fu lfillSales OrderReque st to deac tivate the record. | |||||
| 32 | /// </ summary> | |||||
| 33 | /// <r emarks> | |||||
| 34 | /// At run-time, you will be given t he option to delete all the | |||||
| 35 | /// da tabase rec ords creat ed by this program. | |||||
| 36 | /// </ remarks> | |||||
| 37 | public class Ful fillSalesO rder | |||||
| 38 | { | |||||
| 39 | #r egion Clas s Level Me mbers | |||||
| 40 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 41 | pr ivate Guid ? _salesOr derId; | |||||
| 42 | pr ivate Guid ? _account Id; | |||||
| 43 | #e ndregion | |||||
| 44 | ||||||
| 45 | #r egion How To Sample Code | |||||
| 46 | ||||||
| 47 | // / <summary > | |||||
| 48 | // / Creates a sales or der and sh ows how to close usi ng the Ful fillSalesO rderReques t | |||||
| 49 | // / </summar y> | |||||
| 50 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 51 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 52 | // / created entities.< /param> | |||||
| 53 | pu blic void Run(Server Connection .Configura tion serve rConfig, | |||||
| 54 | bool prom ptforDelet e) | |||||
| 55 | { | |||||
| 56 | using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, serverConf ig.Credent ials, serv erConfig.D eviceCrede ntials)) | |||||
| 57 | { | |||||
| 58 | // T his statem ent is req uired to e nable earl y-bound ty pe support . | |||||
| 59 | _ser viceProxy. EnableProx yTypes(); | |||||
| 60 | ||||||
| 61 | Crea teCustomer (); | |||||
| 62 | Crea teSalesOrd er(); | |||||
| 63 | Clos eSalesOrde r(); | |||||
| 64 | Dele teRequired Records(pr omptforDel ete); | |||||
| 65 | } | |||||
| 66 | } | |||||
| 67 | ||||||
| 68 | // / <summary > | |||||
| 69 | // / Creates a customer for the s ales order | |||||
| 70 | // / </summar y> | |||||
| 71 | pr ivate void CreateCus tomer() | |||||
| 72 | { | |||||
| 73 | // Creat e an accou nt to be u sed with t he sales a ccount. | |||||
| 74 | _account Id = _serv iceProxy.C reate(new Account | |||||
| 75 | { | |||||
| 76 | Name = "Micros oft" | |||||
| 77 | }); | |||||
| 78 | ||||||
| 79 | Console. WriteLine( String.Con cat("Creat ed account for sales order: ", | |||||
| 80 | _acc ountId.Val ue)); | |||||
| 81 | } | |||||
| 82 | ||||||
| 83 | // / <summary > | |||||
| 84 | // / Creates the sales order to c lose | |||||
| 85 | // / </summar y> | |||||
| 86 | pr ivate void CreateSal esOrder() | |||||
| 87 | { | |||||
| 88 | // Creat e a sales order with an accoun t | |||||
| 89 | _salesOr derId = _s erviceProx y.Create(n ew SalesOr der | |||||
| 90 | { | |||||
| 91 | Cust omerId = n ew EntityR eference | |||||
| 92 | { | |||||
| 93 | LogicalNam e = Accoun t.EntityLo gicalName, | |||||
| 94 | Id = _acco untId.Valu e | |||||
| 95 | }, | |||||
| 96 | Desc ription = "Sales Ord er Descrip tion", | |||||
| 97 | }); | |||||
| 98 | ||||||
| 99 | Console. WriteLine( String.Con cat("Creat ed sales o rder: ", | |||||
| 100 | _sal esOrderId. Value)); | |||||
| 101 | } | |||||
| 102 | ||||||
| 103 | // / <summary > | |||||
| 104 | // / Calls th e FulfillS alesOrderR equest and closes it as comple ted | |||||
| 105 | // / </summar y> | |||||
| 106 | pr ivate void CloseSale sOrder() | |||||
| 107 | { | |||||
| 108 | if (!_sa lesOrderId .HasValue) | |||||
| 109 | retu rn; | |||||
| 110 | //<snipp etFulfill1 > | |||||
| 111 | ||||||
| 112 | // Close the sales order wit h a status of Comple te | |||||
| 113 | int newS tatus = (i nt)salesor der_status code.Compl ete; | |||||
| 114 | var requ est = new FulfillSal esOrderReq uest | |||||
| 115 | { | |||||
| 116 | Orde rClose = n ew OrderCl ose | |||||
| 117 | { | |||||
| 118 | SalesOrder Id = new E ntityRefer ence | |||||
| 119 | { Logi calName = SalesOrder .EntityLog icalName, Id = _sale sOrderId.V alue } | |||||
| 120 | ||||||
| 121 | }, | |||||
| 122 | Stat us = new O ptionSetVa lue(newSta tus) | |||||
| 123 | }; | |||||
| 124 | ||||||
| 125 | Console. WriteLine( String.Con cat("Execu ting Fullf illSalesOr derRequest on sales order: ", | |||||
| 126 | _sal esOrderId. Value, ",\ n\t new st atus: ", | |||||
| 127 | GetL abelForSta tus(SalesO rder.Entit yLogicalNa me, "statu scode", ne wStatus))) ; | |||||
| 128 | ||||||
| 129 | _service Proxy.Exec ute(reques t); | |||||
| 130 | //</snip petFulfill 1> | |||||
| 131 | ||||||
| 132 | // Valid ate that t he sales o rder is co mplete | |||||
| 133 | var sale sOrder = _ servicePro xy.Retriev e(SalesOrd er.EntityL ogicalName , _salesOr derId.Valu e, | |||||
| 134 | new ColumnSet( "statuscod e")).ToEnt ity<SalesO rder>(); | |||||
| 135 | ||||||
| 136 | Console. WriteLine( String.Con cat("Valid ation of c losed sale s order: " , _salesOr derId.Valu e, | |||||
| 137 | ",\n \t status: ", salesO rder.Forma ttedValues ["statusco de"])); | |||||
| 138 | } | |||||
| 139 | ||||||
| 140 | // / <summary > | |||||
| 141 | // / Returns the label for a stat us option | |||||
| 142 | // / </summar y> | |||||
| 143 | // / <param n ame="entit y">entity logical na me</param> | |||||
| 144 | // / <param n ame="attri bute">stat uscode </p aram> | |||||
| 145 | // / <param n ame="value ">numeric value</par am> | |||||
| 146 | // / <returns >user labe l</returns > | |||||
| 147 | pr ivate stri ng GetLabe lForStatus (string en tity, stri ng attribu te, int va lue) | |||||
| 148 | { | |||||
| 149 | // Retri eve the at tribute me tadata | |||||
| 150 | var attr ibuteMD = ((Retrieve AttributeR esponse) _ servicePro xy.Execute ( | |||||
| 151 | new RetrieveAt tributeReq uest | |||||
| 152 | { | |||||
| 153 | EntityLogi calName = entity, | |||||
| 154 | LogicalNam e = attrib ute, | |||||
| 155 | RetrieveAs IfPublishe d = true, | |||||
| 156 | })). AttributeM etadata; | |||||
| 157 | ||||||
| 158 | // find the option based on the numeri c value an d return t he label | |||||
| 159 | if (attr ibuteMD.At tributeTyp e == Attri buteTypeCo de.Status) | |||||
| 160 | { | |||||
| 161 | var options = ((StatusAt tributeMet adata)attr ibuteMD).O ptionSet.O ptions; | |||||
| 162 | ||||||
| 163 | var crmOption = options. FirstOrDef ault(x => x.Value == value); | |||||
| 164 | if ( crmOption != null) | |||||
| 165 | return crm Option.Lab el.UserLoc alizedLabe l.Label; | |||||
| 166 | } | |||||
| 167 | ||||||
| 168 | return s tring.Empt y; | |||||
| 169 | } | |||||
| 170 | ||||||
| 171 | // / <summary > | |||||
| 172 | // / | |||||
| 173 | // / </summar y> | |||||
| 174 | // / <param n ame="promp t"></param > | |||||
| 175 | pr ivate void DeleteReq uiredRecor ds(bool pr ompt) | |||||
| 176 | { | |||||
| 177 | bool toB eDeleted = true; | |||||
| 178 | ||||||
| 179 | if (prom pt) | |||||
| 180 | { | |||||
| 181 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 182 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 183 | Stri ng answer = Console. ReadLine() ; | |||||
| 184 | if ( answer.Sta rtsWith("y ") || | |||||
| 185 | answer.Sta rtsWith("Y ") || | |||||
| 186 | answer == String.Emp ty) | |||||
| 187 | { | |||||
| 188 | toBeDelete d = true; | |||||
| 189 | } | |||||
| 190 | else | |||||
| 191 | { | |||||
| 192 | toBeDelete d = false; | |||||
| 193 | } | |||||
| 194 | } | |||||
| 195 | ||||||
| 196 | if (toBe Deleted) | |||||
| 197 | { | |||||
| 198 | // D elete reco rds create d in this sample. D elete the sales orde r first | |||||
| 199 | // o r there wi ll be an e rror due t o restrict delete. | |||||
| 200 | if ( _salesOrde rId.HasVal ue) | |||||
| 201 | { | |||||
| 202 | Console.Wr iteLine(St ring.Conca t("Deletin g sales or der: ", _s alesOrderI d.Value)); | |||||
| 203 | _servicePr oxy.Delete (SalesOrde r.EntityLo gicalName, _salesOrd erId.Value ); | |||||
| 204 | } | |||||
| 205 | if ( _accountId .HasValue) | |||||
| 206 | { | |||||
| 207 | Console.Wr iteLine(St ring.Conca t("Deletin g account: ", _accou ntId.Value )); | |||||
| 208 | _servicePr oxy.Delete (Account.E ntityLogic alName, _a ccountId.V alue); | |||||
| 209 | } | |||||
| 210 | ||||||
| 211 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 212 | } | |||||
| 213 | } | |||||
| 214 | ||||||
| 215 | #e ndregion | |||||
| 216 | ||||||
| 217 | #r egion Main method | |||||
| 218 | // / <summary > | |||||
| 219 | // / Standard Main() me thod used by most SD K samples. | |||||
| 220 | // / </summar y> | |||||
| 221 | // / <param n ame="args" ></param> | |||||
| 222 | st atic publi c void Mai n(string[] args) | |||||
| 223 | { | |||||
| 224 | try | |||||
| 225 | { | |||||
| 226 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 227 | // c redentials from the user. | |||||
| 228 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 229 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 230 | ||||||
| 231 | var app = new FulfillSal esOrder(); | |||||
| 232 | app. Run(config , true); | |||||
| 233 | } | |||||
| 234 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 235 | { | |||||
| 236 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 237 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 238 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 239 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 240 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 241 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 242 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 243 | } | |||||
| 244 | catch (S ystem.Time outExcepti on ex) | |||||
| 245 | { | |||||
| 246 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 247 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 248 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 249 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 250 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 251 | } | |||||
| 252 | catch (S ystem.Exce ption ex) | |||||
| 253 | { | |||||
| 254 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 255 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 256 | ||||||
| 257 | // D isplay the details o f the inne r exceptio n. | |||||
| 258 | if ( ex.InnerEx ception != null) | |||||
| 259 | { | |||||
| 260 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 261 | ||||||
| 262 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 263 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 264 | if (fe != null) | |||||
| 265 | { | |||||
| 266 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 267 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 268 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 269 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 270 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 271 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 272 | } | |||||
| 273 | } | |||||
| 274 | } | |||||
| 275 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 276 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 277 | ||||||
| 278 | finally | |||||
| 279 | { | |||||
| 280 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 281 | Cons ole.ReadLi ne(); | |||||
| 282 | } | |||||
| 283 | } | |||||
| 284 | #e ndregion | |||||
| 285 | } | |||||
| 286 | } | |||||
| 287 | //</snippe tFulfillSa lesOrder> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.