Produced by Araxis Merge on 2/1/2017 2:56:47 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\Metadata\Entities | CreateUpdateEntityMetadata.cs | Tue Dec 20 19:51:46 2016 UTC |
| 2 | Wed Feb 1 19:56:47 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 617 |
| 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 | // | |||||
| 3 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 4 | // | |||||
| 5 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 6 | // | |||||
| 7 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 8 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 9 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 10 | // | |||||
| 11 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 12 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 13 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 14 | // PARTIC ULAR PURPO SE. | |||||
| 15 | // | |||||
| 16 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 17 | //<snippet CreateUpda teEntityMe tadata> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Syst em.Service Model.Desc ription; | |||||
| 21 | using Syst em.Diagnos tics; | |||||
| 22 | using Syst em.Xml.Lin q; | |||||
| 23 | ||||||
| 24 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 25 | // found i n the SDK\ bin folder . | |||||
| 26 | using Micr osoft.Xrm. Sdk; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 30 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 31 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 32 | ||||||
| 33 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 34 | // found i n the SDK\ bin folder . | |||||
| 35 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 36 | ||||||
| 37 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 38 | { | |||||
| 39 | public class Cre ateUpdateE ntityMetad ata | |||||
| 40 | { | |||||
| 41 | #r egion Clas s Level Me mbers | |||||
| 42 | // / <summary > | |||||
| 43 | // / Stores t he organiz ation serv ice proxy. | |||||
| 44 | // / </summar y> | |||||
| 45 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 46 | ||||||
| 47 | pr ivate cons t String _ customEnti tyName = " new_bankac count"; | |||||
| 48 | ||||||
| 49 | #e ndregion C lass Level Members | |||||
| 50 | ||||||
| 51 | #r egion How To Sample Code | |||||
| 52 | // / <summary > | |||||
| 53 | // / Create a custom en tity. | |||||
| 54 | // / Update t he custom entity. | |||||
| 55 | // / Optional ly delete the custom entity. | |||||
| 56 | // / </summar y> | |||||
| 57 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 58 | // / <param n ame="promp tForDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 59 | // / created entities.< /param> | |||||
| 60 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 61 | { | |||||
| 62 | try | |||||
| 63 | { | |||||
| 64 | ||||||
| 65 | // C onnect to the Organi zation ser vice. | |||||
| 66 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 67 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, serve rConfig.Cr edentials, serverCon fig.Device Credential s)) | |||||
| 68 | { | |||||
| 69 | // This st atement is required to enable early-boun d type sup port. | |||||
| 70 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 71 | ||||||
| 72 | ||||||
| 73 | // Create the custom entity. | |||||
| 74 | //<snippet CreateUpda teEntityMe tadata1> | |||||
| 75 | CreateEnti tyRequest createrequ est = new CreateEnti tyRequest | |||||
| 76 | { | |||||
| 77 | ||||||
| 78 | //Defi ne the ent ity | |||||
| 79 | Entity = new Ent ityMetadat a | |||||
| 80 | { | |||||
| 81 | Sc hemaName = _customEn tityName, | |||||
| 82 | Di splayName = new Labe l("Bank Ac count", 10 33), | |||||
| 83 | Di splayColle ctionName = new Labe l("Bank Ac counts", 1 033), | |||||
| 84 | De scription = new Labe l("An enti ty to stor e informat ion about customer b ank accoun ts", 1033) , | |||||
| 85 | Ow nershipTyp e = Owners hipTypes.U serOwned, | |||||
| 86 | Is Activity = false, | |||||
| 87 | ||||||
| 88 | }, | |||||
| 89 | ||||||
| 90 | // Def ine the pr imary attr ibute for the entity | |||||
| 91 | Primar yAttribute = new Str ingAttribu teMetadata | |||||
| 92 | { | |||||
| 93 | Sc hemaName = "new_acco untname", | |||||
| 94 | Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.N one), | |||||
| 95 | Ma xLength = 100, | |||||
| 96 | Fo rmatName = StringFor matName.Te xt, | |||||
| 97 | Di splayName = new Labe l("Account Name", 10 33), | |||||
| 98 | De scription = new Labe l("The pri mary attri bute for t he Bank Ac count enti ty.", 1033 ) | |||||
| 99 | } | |||||
| 100 | ||||||
| 101 | }; | |||||
| 102 | _servicePr oxy.Execut e(createre quest); | |||||
| 103 | Console.Wr iteLine("T he Bank Ac count cust om entity has been c reated."); | |||||
| 104 | //</snippe tCreateUpd ateEntityM etadata1> | |||||
| 105 | ||||||
| 106 | ||||||
| 107 | // Add som e attribut es to the Bank Accou nt entity | |||||
| 108 | //<snippet CreateUpda teEntityMe tadata2> | |||||
| 109 | CreateAttr ibuteReque st createB ankNameAtt ributeRequ est = new CreateAttr ibuteReque st | |||||
| 110 | { | |||||
| 111 | Entity Name = _cu stomEntity Name, | |||||
| 112 | Attrib ute = new StringAttr ibuteMetad ata | |||||
| 113 | { | |||||
| 114 | Sc hemaName = "new_bank name", | |||||
| 115 | Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.N one), | |||||
| 116 | Ma xLength = 100, | |||||
| 117 | Fo rmatName = StringFor matName.Te xt, | |||||
| 118 | Di splayName = new Labe l("Bank Na me", 1033) , | |||||
| 119 | De scription = new Labe l("The nam e of the b ank.", 103 3) | |||||
| 120 | } | |||||
| 121 | }; | |||||
| 122 | ||||||
| 123 | _servicePr oxy.Execut e(createBa nkNameAttr ibuteReque st); | |||||
| 124 | //</snippe tCreateUpd ateEntityM etadata2> | |||||
| 125 | Console.Wr iteLine("\ nA Bank Na me attribu te has bee n added to the Bank Account en tity."); | |||||
| 126 | ||||||
| 127 | //<snippet CreateUpda teEntityMe tadata3> | |||||
| 128 | CreateAttr ibuteReque st createB alanceAttr ibuteReque st = new C reateAttri buteReques t | |||||
| 129 | { | |||||
| 130 | Entity Name = _cu stomEntity Name, | |||||
| 131 | Attrib ute = new MoneyAttri buteMetada ta | |||||
| 132 | { | |||||
| 133 | Sc hemaName = "new_bala nce", | |||||
| 134 | Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.N one), | |||||
| 135 | Pr ecisionSou rce = 2, | |||||
| 136 | Di splayName = new Labe l("Balance ", 1033), | |||||
| 137 | De scription = new Labe l("Account Balance a t the last known dat e", 1033), | |||||
| 138 | ||||||
| 139 | } | |||||
| 140 | }; | |||||
| 141 | ||||||
| 142 | _servicePr oxy.Execut e(createBa lanceAttri buteReques t); | |||||
| 143 | //</snippe tCreateUpd ateEntityM etadata3> | |||||
| 144 | Console.Wr iteLine("A Balance a ttribute h as been ad ded to the Bank Acco unt entity ."); | |||||
| 145 | ||||||
| 146 | //<snippet CreateUpda teEntityMe tadata4> | |||||
| 147 | CreateAttr ibuteReque st createC heckedDate Request = new Create AttributeR equest | |||||
| 148 | { | |||||
| 149 | Entity Name = _cu stomEntity Name, | |||||
| 150 | Attrib ute = new DateTimeAt tributeMet adata | |||||
| 151 | { | |||||
| 152 | Sc hemaName = "new_chec keddate", | |||||
| 153 | Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.N one), | |||||
| 154 | Fo rmat = Dat eTimeForma t.DateOnly , | |||||
| 155 | Di splayName = new Labe l("Date", 1033), | |||||
| 156 | De scription = new Labe l("The dat e the acco unt balanc e was last confirmed ", 1033) | |||||
| 157 | ||||||
| 158 | } | |||||
| 159 | }; | |||||
| 160 | ||||||
| 161 | _servicePr oxy.Execut e(createCh eckedDateR equest); | |||||
| 162 | Console.Wr iteLine("A date attr ibute has been added to the Ba nk Account entity.") ; | |||||
| 163 | //</snippe tCreateUpd ateEntityM etadata4> | |||||
| 164 | ||||||
| 165 | ||||||
| 166 | //Create a customer lookup att ribute to link the b ank accoun t with an account or a contact record. | |||||
| 167 | //<snippet CreateUpda teEntityMe tadata13> | |||||
| 168 | CreateCust omerRelati onshipsReq uest creat eCustomerR eq = new C reateCusto merRelatio nshipsRequ est | |||||
| 169 | { | |||||
| 170 | Lookup = new Loo kupAttribu teMetadata | |||||
| 171 | { | |||||
| 172 | De scription = new Labe l("The own er of the bank accou nt", 1033) , | |||||
| 173 | Di splayName = new Labe l("Account owner", 1 033), | |||||
| 174 | Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.A pplication Required), | |||||
| 175 | Sc hemaName = "new_cust omerid" | |||||
| 176 | }, | |||||
| 177 | OneToM anyRelatio nships = n ew OneToMa nyRelation shipMetada ta[] | |||||
| 178 | { | |||||
| 179 | ne w OneToMan yRelations hipMetadat a() | |||||
| 180 | { | |||||
| 181 | Referenc edEntity = "account" , | |||||
| 182 | Referenc ingEntity = _customE ntityName, | |||||
| 183 | SchemaNa me = "new_ bankaccoun t_customer _account", | |||||
| 184 | }, | |||||
| 185 | ne w OneToMan yRelations hipMetadat a() | |||||
| 186 | { | |||||
| 187 | Referenc edEntity = "contact" , | |||||
| 188 | Referenc ingEntity = _customE ntityName, | |||||
| 189 | SchemaNa me = "new_ bankaccoun t_customer _contact", | |||||
| 190 | } | |||||
| 191 | }, | |||||
| 192 | }; | |||||
| 193 | _servicePr oxy.Execut e(createCu stomerReq) ; | |||||
| 194 | //</snippe tCreateUpd ateEntityM etadata13> | |||||
| 195 | Console.Wr iteLine("A customer lookup att ribute has been adde d to the B ank Accoun t entity \ nto link i t with the Account o r Contact entity."); | |||||
| 196 | ||||||
| 197 | ||||||
| 198 | //Create a lookup at tribute to link the bank accou nt with a contact re cord. | |||||
| 199 | //<snippet CreateUpda teEntityMe tadata5> | |||||
| 200 | CreateOneT oManyReque st req = n ew CreateO neToManyRe quest() | |||||
| 201 | { | |||||
| 202 | Lookup = new Loo kupAttribu teMetadata () | |||||
| 203 | { | |||||
| 204 | De scription = new Labe l("The ref erral (lea d) from th e bank acc ount owner ", 1033), | |||||
| 205 | Di splayName = new Labe l("Referra l", 1033), | |||||
| 206 | Lo gicalName = "new_par ent_leadid ", | |||||
| 207 | Sc hemaName = "New_Pare nt_leadId" , | |||||
| 208 | Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.R ecommended ) | |||||
| 209 | }, | |||||
| 210 | OneToM anyRelatio nship = ne w OneToMan yRelations hipMetadat a() | |||||
| 211 | { | |||||
| 212 | As sociatedMe nuConfigur ation = ne w Associat edMenuConf iguration( ) | |||||
| 213 | { | |||||
| 214 | Behavior = Associa tedMenuBeh avior.UseC ollectionN ame, | |||||
| 215 | Group = Associated MenuGroup. Details, | |||||
| 216 | Label = new Label( "Bank Acco unts", 103 3), | |||||
| 217 | Order = 10000 | |||||
| 218 | }, | |||||
| 219 | Ca scadeConfi guration = new Casca deConfigur ation() | |||||
| 220 | { | |||||
| 221 | Assign = CascadeTy pe.Cascade , | |||||
| 222 | Delete = CascadeTy pe.Cascade , | |||||
| 223 | Merge = CascadeTyp e.Cascade, | |||||
| 224 | Reparent = Cascade Type.Casca de, | |||||
| 225 | Share = CascadeTyp e.Cascade, | |||||
| 226 | Unshare = CascadeT ype.Cascad e | |||||
| 227 | }, | |||||
| 228 | Re ferencedEn tity = "le ad", | |||||
| 229 | Re ferencedAt tribute = "leadid", | |||||
| 230 | Re ferencingE ntity = _c ustomEntit yName, | |||||
| 231 | Sc hemaName = "new_lead _new_banka ccount" | |||||
| 232 | } | |||||
| 233 | }; | |||||
| 234 | _servicePr oxy.Execut e(req); | |||||
| 235 | //</snippe tCreateUpd ateEntityM etadata5> | |||||
| 236 | Console.Wr iteLine("A lookup at tribute ha s been add ed to the Bank Accou nt entity \nto link it with th e Lead ent ity."); | |||||
| 237 | ||||||
| 238 | //<snippet CreateUpda teEntityMe tadata11> | |||||
| 239 | //Create a n Image at tribute fo r the cust om entity | |||||
| 240 | // Only on e Image at tribute ca n be added to an ent ity that d oesn't alr eady have one. | |||||
| 241 | CreateAttr ibuteReque st createE ntityImage Request = new Create AttributeR equest | |||||
| 242 | { | |||||
| 243 | Entity Name = _cu stomEntity Name, | |||||
| 244 | Attrib ute = new ImageAttri buteMetada ta | |||||
| 245 | { | |||||
| 246 | Sc hemaName = "EntityIm age", //Th e name is always Ent ityImage | |||||
| 247 | Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.N one), | |||||
| 248 | Di splayName = new Labe l("Image", 1033), | |||||
| 249 | De scription = new Labe l("An imag e to repre sent the b ank accoun t.", 1033) | |||||
| 250 | ||||||
| 251 | } | |||||
| 252 | }; | |||||
| 253 | ||||||
| 254 | _servicePr oxy.Execut e(createEn tityImageR equest); | |||||
| 255 | Console.Wr iteLine("A n image at tribute ha s been add ed to the Bank Accou nt entity. "); | |||||
| 256 | //</snippe tCreateUpd ateEntityM etadata11> | |||||
| 257 | ||||||
| 258 | //<snippet CreateUpda teEntityMe tadata9> | |||||
| 259 | ||||||
| 260 | //<snippet CreateUpda teEntityMe tadata.Ret rieveEntit y> | |||||
| 261 | RetrieveEn tityReques t retrieve BankAccoun tEntityReq uest = new RetrieveE ntityReque st | |||||
| 262 | { | |||||
| 263 | Entity Filters = EntityFilt ers.Entity , | |||||
| 264 | Logica lName = _c ustomEntit yName | |||||
| 265 | }; | |||||
| 266 | RetrieveEn tityRespon se retriev eBankAccou ntEntityRe sponse = ( RetrieveEn tityRespon se)_servic eProxy.Exe cute(retri eveBankAcc ountEntity Request); | |||||
| 267 | //</snippe tCreateUpd ateEntityM etadata.Re trieveEnti ty> | |||||
| 268 | //<snippet CreateUpda teEntityMe tadata8> | |||||
| 269 | EntityMeta data BankA ccountEnti ty = retri eveBankAcc ountEntity Response.E ntityMetad ata; | |||||
| 270 | ||||||
| 271 | // Disable Mail merg e | |||||
| 272 | BankAccoun tEntity.Is MailMergeE nabled = n ew Boolean ManagedPro perty(fals e); | |||||
| 273 | // Enable Notes | |||||
| 274 | UpdateEnti tyRequest updateBank AccountReq uest = new UpdateEnt ityRequest | |||||
| 275 | { | |||||
| 276 | Entity = BankAcc ountEntity , | |||||
| 277 | HasNot es = true | |||||
| 278 | }; | |||||
| 279 | ||||||
| 280 | ||||||
| 281 | ||||||
| 282 | _servicePr oxy.Execut e(updateBa nkAccountR equest); | |||||
| 283 | //</snippe tCreateUpd ateEntityM etadata8> | |||||
| 284 | //</snippe tCreateUpd ateEntityM etadata9> | |||||
| 285 | ||||||
| 286 | Console.Wr iteLine("\ nThe Bank Account en tity has b een update d"); | |||||
| 287 | ||||||
| 288 | ||||||
| 289 | //Update t he entity form so th e new fiel ds are vis ible | |||||
| 290 | UpdateEnti tyForm(_cu stomEntity Name); | |||||
| 291 | ||||||
| 292 | // Customi zations mu st be publ ished afte r an entit y is updat ed. | |||||
| 293 | //<snippet CreateUpda teEntityMe tadata6> | |||||
| 294 | PublishAll XmlRequest publishRe quest = ne w PublishA llXmlReque st(); | |||||
| 295 | _servicePr oxy.Execut e(publishR equest); | |||||
| 296 | //</snippe tCreateUpd ateEntityM etadata6> | |||||
| 297 | Console.Wr iteLine("\ nCustomiza tions were published ."); | |||||
| 298 | ||||||
| 299 | //Provides option to view the entity in the defaul t solution | |||||
| 300 | ShowEntity InBrowser( promptForD elete, Ban kAccountEn tity); | |||||
| 301 | //Provides option to view the entity for m with the fields ad ded | |||||
| 302 | ShowEntity FormInBrow ser(prompt ForDelete, BankAccou ntEntity); | |||||
| 303 | ||||||
| 304 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 305 | } | |||||
| 306 | } | |||||
| 307 | ||||||
| 308 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 309 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 310 | { | |||||
| 311 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 312 | thro w; | |||||
| 313 | } | |||||
| 314 | } | |||||
| 315 | ||||||
| 316 | // / <summary > | |||||
| 317 | // / Deletes the custom entity th at was cre ated for t his sample . | |||||
| 318 | // / <param n ame="promp t">Indicat es whether to prompt the user to delete the record s created in this sa mple.</par am> | |||||
| 319 | // / </summar y> | |||||
| 320 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 321 | { | |||||
| 322 | bool del eteEntity = true; | |||||
| 323 | ||||||
| 324 | if (prom pt) | |||||
| 325 | { | |||||
| 326 | Cons ole.WriteL ine("\nDo you want t he Bank Ac count cust om entity deleted? ( y/n)"); | |||||
| 327 | Stri ng answer = Console. ReadLine() ; | |||||
| 328 | ||||||
| 329 | dele teEntity = (answer.S tartsWith( "y") || an swer.Start sWith("Y") ); | |||||
| 330 | } | |||||
| 331 | ||||||
| 332 | if (dele teEntity) | |||||
| 333 | { | |||||
| 334 | //<s nippetCrea teUpdateEn tityMetada ta10> | |||||
| 335 | Dele teEntityRe quest requ est = new DeleteEnti tyRequest( ) | |||||
| 336 | { | |||||
| 337 | LogicalNam e = _custo mEntityNam e, | |||||
| 338 | }; | |||||
| 339 | _ser viceProxy. Execute(re quest); | |||||
| 340 | //</ snippetCre ateUpdateE ntityMetad ata10> | |||||
| 341 | Cons ole.WriteL ine("The c ustom enti ty has bee n deleted. "); | |||||
| 342 | } | |||||
| 343 | } | |||||
| 344 | ||||||
| 345 | pu blic void ShowEntity InBrowser( bool promp t, EntityM etadata Ba nkAccountE ntity) | |||||
| 346 | { | |||||
| 347 | ||||||
| 348 | if (prom pt) | |||||
| 349 | { | |||||
| 350 | ||||||
| 351 | Cons ole.WriteL ine("\nDo you want t o view the Bank Acco unt custom entity in the defau lt solutio n? (y/n)") ; | |||||
| 352 | Stri ng answer = Console. ReadLine() ; | |||||
| 353 | if ( answer.Sta rtsWith("y ") || answ er.StartsW ith("Y")) | |||||
| 354 | { | |||||
| 355 | ||||||
| 356 | try | |||||
| 357 | { | |||||
| 358 | String webServic eURL = _se rviceProxy .EndpointS witch.Prim aryEndpoin t.Absolute Uri; | |||||
| 359 | String entityInD efaultSolu tionUrl = webService URL.Replac e("XRMServ ices/2011/ Organizati on.svc", | |||||
| 360 | Strin g.Format(" tools/solu tion/edit. aspx?def_c ategory=98 01&def_typ e={0}&id=% 7bFD140AAF -4DF4-11DD -BD17-0019 B9312238%7 d", BankAc countEntit y.ObjectTy peCode)); | |||||
| 361 | ||||||
| 362 | Proces sStartInfo browserPr ocess = ne w ProcessS tartInfo(" iexplore.e xe"); | |||||
| 363 | browse rProcess.A rguments = entityInD efaultSolu tionUrl; | |||||
| 364 | Proces s.Start(br owserProce ss); | |||||
| 365 | ||||||
| 366 | } | |||||
| 367 | catch (Sys temExcepti on) | |||||
| 368 | { | |||||
| 369 | Consol e.WriteLin e("\nThere was a pro blem openi ng Interne t Explorer ."); | |||||
| 370 | } | |||||
| 371 | ||||||
| 372 | } | |||||
| 373 | ||||||
| 374 | } | |||||
| 375 | ||||||
| 376 | ||||||
| 377 | } | |||||
| 378 | ||||||
| 379 | pu blic void ShowEntity FormInBrow ser(bool p rompt, Ent ityMetadat a BankAcco untEntity) | |||||
| 380 | { | |||||
| 381 | if (prom pt) | |||||
| 382 | { | |||||
| 383 | Cons ole.WriteL ine("\nDo you want t o view the form for this entit y? (y/n)") ; | |||||
| 384 | Stri ng viewFor mAnswer = Console.Re adLine(); | |||||
| 385 | if ( viewFormAn swer.Start sWith("y") || viewFo rmAnswer.S tartsWith( "Y")) | |||||
| 386 | { | |||||
| 387 | try | |||||
| 388 | { | |||||
| 389 | String webServic eURL = _se rviceProxy .EndpointS witch.Prim aryEndpoin t.Absolute Uri; | |||||
| 390 | String entityInD efaultSolu tionUrl = webService URL.Replac e("XRMServ ices/2011/ Organizati on.svc", | |||||
| 391 | Strin g.Format(" main.aspx? etn={0}&pa getype=ent ityrecord" , BankAcco untEntity. LogicalNam e)); | |||||
| 392 | ||||||
| 393 | Proces sStartInfo browserPr ocess = ne w ProcessS tartInfo(" iexplore.e xe"); | |||||
| 394 | browse rProcess.A rguments = entityInD efaultSolu tionUrl; | |||||
| 395 | Proces s.Start(br owserProce ss); | |||||
| 396 | ||||||
| 397 | } | |||||
| 398 | catch (Sys temExcepti on) | |||||
| 399 | { | |||||
| 400 | Consol e.WriteLin e("\nThere was a pro blem openi ng Interne t Explorer ."); | |||||
| 401 | } | |||||
| 402 | } | |||||
| 403 | } | |||||
| 404 | } | |||||
| 405 | // <snippetCr eateUpdate EntityMeta data12> | |||||
| 406 | // / <summary > | |||||
| 407 | // / Updates the formXm l to add a new tab c ontaining the fields added by this sampl e. | |||||
| 408 | // / <param n ame="entit yLogicalNa me">The lo gical name of the ne w_bankacco unt entity used in t his sample </param> | |||||
| 409 | // / </summar y> | |||||
| 410 | pu blic void UpdateEnti tyForm(Str ing entity LogicalNam e) | |||||
| 411 | { | |||||
| 412 | ||||||
| 413 | QueryExp ression qe = new Que ryExpressi on("system form"); | |||||
| 414 | qe.Crite ria.AddCon dition("ty pe", Condi tionOperat or.Equal, 2); //main form | |||||
| 415 | qe.Crite ria.AddCon dition("ob jecttypeco de", Condi tionOperat or.Equal, entityLogi calName); //for new_ bankaccoun t entity | |||||
| 416 | qe.Colum nSet.AddCo lumn("form xml"); | |||||
| 417 | //Retrie ve the fir st main en tity form for this e ntity | |||||
| 418 | SystemFo rm bankAcc ountMainFo rm = (Syst emForm)_se rviceProxy .RetrieveM ultiple(qe ).Entities [0]; | |||||
| 419 | ||||||
| 420 | XDocumen t bankAcco untFormXml = XDocume nt.Parse(b ankAccount MainForm.F ormXml); | |||||
| 421 | //Set th e showImag e attribut e so the e ntity imag e will be displayed | |||||
| 422 | bankAcco untFormXml .Root.SetA ttributeVa lue("showI mage", tru e); | |||||
| 423 | ||||||
| 424 | // Defin ition of a custom ta b containi ng the cus tom attrib utes creat ed in this sample | |||||
| 425 | String f ormTabXmlS tring = @" <tab name= ""custom_a ttributes" " | |||||
| 426 | id= ""{824792c 4-ea85-150 4-40e2-b78 0b26dc6ab} "" | |||||
| 427 | IsU serDefined =""0"" | |||||
| 428 | loc klevel=""0 "" | |||||
| 429 | sho wlabel=""t rue"" | |||||
| 430 | exp anded=""tr ue""> | |||||
| 431 | <labels > | |||||
| 432 | <label descripti on=""Custo m Attribut es"" | |||||
| 433 | languagec ode=""1033 "" /> | |||||
| 434 | </label s> | |||||
| 435 | <column s> | |||||
| 436 | <colum n width="" 100%""> | |||||
| 437 | <sect ions> | |||||
| 438 | <sec tion name= ""custom_s ection"" | |||||
| 439 | showl abel=""fal se"" | |||||
| 440 | showb ar=""false "" | |||||
| 441 | lockl evel=""0"" | |||||
| 442 | id="" {9bda81ec- e41b-7a4d- 08b4-4536c 5862ce1}"" | |||||
| 443 | IsUse rDefined=" "0"" | |||||
| 444 | layou t=""varwid th"" | |||||
| 445 | colum ns=""1"" | |||||
| 446 | label width=""11 5"" | |||||
| 447 | celll abelalignm ent=""Left "" | |||||
| 448 | celll abelpositi on=""Left" "> | |||||
| 449 | <la bels> | |||||
| 450 | <l abel descr iption=""S ection"" | |||||
| 451 | langu agecode="" 1033"" /> | |||||
| 452 | </l abels> | |||||
| 453 | <ro ws> | |||||
| 454 | <r ow> | |||||
| 455 | < cell id="" {99FF4728- D8D7-47D3- B046-7BEFC BFB4319}"" | |||||
| 456 | showl abel=""tru e"" | |||||
| 457 | lockl evel=""0"" > | |||||
| 458 | <labels> | |||||
| 459 | <label de scription= ""Account Owner"" | |||||
| 460 | la nguagecode =""1033"" /> | |||||
| 461 | </labels> | |||||
| 462 | <control i d=""new_cu stomerid"" | |||||
| 463 | c lassid=""{ 270BD3DB-D 9AF-4782-9 025-509E29 8DEC0A}"" | |||||
| 464 | d atafieldna me=""new_c ustomerid" " | |||||
| 465 | d isabled="" false"" /> | |||||
| 466 | </cell> | |||||
| 467 | </ row> | |||||
| 468 | <r ow> | |||||
| 469 | < cell id="" {6e5975d3- 64b5-14eb- 00e4-064e3 dd298b9}"" | |||||
| 470 | showl abel=""tru e"" | |||||
| 471 | lockl evel=""0"" > | |||||
| 472 | <labels> | |||||
| 473 | <label de scription= ""Bank Nam e"" | |||||
| 474 | la nguagecode =""1033"" /> | |||||
| 475 | </labels> | |||||
| 476 | <control i d=""new_ba nkname"" | |||||
| 477 | c lassid=""{ 4273EDBD-A C1D-40d3-9 FB2-095C62 1B552D}"" | |||||
| 478 | d atafieldna me=""new_b ankname"" | |||||
| 479 | d isabled="" false"" /> | |||||
| 480 | < /cell> | |||||
| 481 | </ row> | |||||
| 482 | <r ow> | |||||
| 483 | < cell id="" {3b436dba- 6156-42e9- 697b-e275d 373505b}"" | |||||
| 484 | showl abel=""tru e"" | |||||
| 485 | lockl evel=""0"" > | |||||
| 486 | <labels> | |||||
| 487 | <label de scription= ""Balance" " | |||||
| 488 | la nguagecode =""1033"" /> | |||||
| 489 | </labels> | |||||
| 490 | <control i d=""new_ba lance"" | |||||
| 491 | c lassid=""{ 533B9E00-7 56B-4312-9 5A0-DC8886 37AC78}"" | |||||
| 492 | d atafieldna me=""new_b alance"" | |||||
| 493 | d isabled="" false"" /> | |||||
| 494 | < /cell> | |||||
| 495 | </ row> | |||||
| 496 | <r ow> | |||||
| 497 | < cell id="" {0e9a3d8a- bd69-71ad- 4ca4-2dcd1 0858719}"" | |||||
| 498 | showl abel=""tru e"" | |||||
| 499 | lockl evel=""0"" > | |||||
| 500 | <labels> | |||||
| 501 | <label de scription= ""Date"" | |||||
| 502 | la nguagecode =""1033"" /> | |||||
| 503 | </labels> | |||||
| 504 | <control i d=""new_ch eckeddate" " | |||||
| 505 | c lassid=""{ 5B773807-9 FB2-42db-9 7C3-7A91EF F8ADFF}"" | |||||
| 506 | d atafieldna me=""new_c heckeddate "" | |||||
| 507 | d isabled="" false"" /> | |||||
| 508 | < /cell> | |||||
| 509 | </ row> | |||||
| 510 | <r ow> | |||||
| 511 | < cell id="" {04b95931- 78c7-6913- a005-922d2 0e521b7}"" | |||||
| 512 | showl abel=""tru e"" | |||||
| 513 | lockl evel=""0"" > | |||||
| 514 | <labels> | |||||
| 515 | <label de scription= ""Referral "" | |||||
| 516 | la nguagecode =""1033"" /> | |||||
| 517 | </labels> | |||||
| 518 | <control i d=""new_pa rent_leadi d"" | |||||
| 519 | c lassid=""{ 270BD3DB-D 9AF-4782-9 025-509E29 8DEC0A}"" | |||||
| 520 | d atafieldna me=""new_p arent_lead id"" | |||||
| 521 | d isabled="" false"" /> | |||||
| 522 | < /cell> | |||||
| 523 | </ row> | |||||
| 524 | </r ows> | |||||
| 525 | </se ction> | |||||
| 526 | </sec tions> | |||||
| 527 | </colu mn> | |||||
| 528 | </colum ns> | |||||
| 529 | </tab>"; | |||||
| 530 | ||||||
| 531 | XDocumen t formTabX ml = XDocu ment.Parse (formTabXm lString); | |||||
| 532 | ||||||
| 533 | //Adding this tab to the tab s element | |||||
| 534 | bankAcco untFormXml .Root.Elem ent("tabs" ).Add(form TabXml.Roo t); | |||||
| 535 | //Update ing the en tity form definition | |||||
| 536 | bankAcco untMainFor m.FormXml = bankAcco untFormXml .ToString( ); | |||||
| 537 | //saving the bank account fo rm | |||||
| 538 | _service Proxy.Upda te(bankAcc ountMainFo rm); | |||||
| 539 | ||||||
| 540 | } | |||||
| 541 | // </snippetC reateUpdat eEntityMet adata12> | |||||
| 542 | #e ndregion H ow To Samp le Code | |||||
| 543 | ||||||
| 544 | #r egion Main | |||||
| 545 | // / <summary > | |||||
| 546 | // / Standard Main() me thod used by most SD K samples. | |||||
| 547 | // / </summar y> | |||||
| 548 | // / <param n ame="args" ></param> | |||||
| 549 | st atic publi c void Mai n(string[] args) | |||||
| 550 | { | |||||
| 551 | try | |||||
| 552 | { | |||||
| 553 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 554 | // c redentials from the user. | |||||
| 555 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 556 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 557 | ||||||
| 558 | Crea teUpdateEn tityMetada ta app = n ew CreateU pdateEntit yMetadata( ); | |||||
| 559 | app. Run(config , true); | |||||
| 560 | } | |||||
| 561 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 562 | { | |||||
| 563 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 564 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 565 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 566 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 567 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 568 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 569 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 570 | } | |||||
| 571 | catch (S ystem.Time outExcepti on ex) | |||||
| 572 | { | |||||
| 573 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 574 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 575 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 576 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 577 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 578 | } | |||||
| 579 | catch (S ystem.Exce ption ex) | |||||
| 580 | { | |||||
| 581 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 582 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 583 | ||||||
| 584 | // D isplay the details o f the inne r exceptio n. | |||||
| 585 | if ( ex.InnerEx ception != null) | |||||
| 586 | { | |||||
| 587 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 588 | ||||||
| 589 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 590 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 591 | if (fe != null) | |||||
| 592 | { | |||||
| 593 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 594 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 595 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 596 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 597 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 598 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 599 | } | |||||
| 600 | } | |||||
| 601 | } | |||||
| 602 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 603 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 604 | ||||||
| 605 | finally | |||||
| 606 | { | |||||
| 607 | ||||||
| 608 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 609 | Cons ole.ReadLi ne(); | |||||
| 610 | } | |||||
| 611 | ||||||
| 612 | } | |||||
| 613 | #e ndregion M ain | |||||
| 614 | ||||||
| 615 | } | |||||
| 616 | } | |||||
| 617 | //</snippe tCreateUpd ateEntityM etadata> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.