Produced by Araxis Merge on 2/1/2017 2:56:46 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\Attributes | WorkWithAttributes.cs | Tue Dec 20 19:51:47 2016 UTC |
| 2 | Wed Feb 1 19:56:46 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 613 |
| 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 WorkWithAt tributes> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Linq; | |||||
| 20 | using Syst em.Xml.Lin q; | |||||
| 21 | using Syst em.Service Model; | |||||
| 22 | using Syst em.Service Model.Desc ription; | |||||
| 23 | using Syst em.Collect ions.Gener ic; | |||||
| 24 | ||||||
| 25 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 26 | // found i n the SDK\ bin folder . | |||||
| 27 | using Micr osoft.Xrm. Sdk; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 30 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 31 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 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 | /// <s ummary> | |||||
| 40 | /// Th is sample shows how to create, retrieve, update an d delete a ttribute. | |||||
| 41 | /// </ summary> | |||||
| 42 | public class Wor kWithAttri butes | |||||
| 43 | { | |||||
| 44 | #r egion Clas s Level Me mbers | |||||
| 45 | ||||||
| 46 | // / <summary > | |||||
| 47 | // / Stores t he organiz ation serv ice proxy. | |||||
| 48 | // / </summar y> | |||||
| 49 | Or ganization ServicePro xy _servic eProxy; | |||||
| 50 | ||||||
| 51 | // Create st orage for new attrib utes being created | |||||
| 52 | pu blic List< AttributeM etadata> a ddedAttrib utes; | |||||
| 53 | ||||||
| 54 | // Specify w hich langu age code t o use in t he sample. If you ar e using a language | |||||
| 55 | // other tha n US Engli sh, you wi ll need to modify th is value a ccordingly . | |||||
| 56 | // See http: //msdn.mic rosoft.com /en-us/lib rary/0h88f ahh.aspx | |||||
| 57 | pu blic const int _lang uageCode = 1033; | |||||
| 58 | ||||||
| 59 | // Define th e IDs/vari ables need ed for thi s sample. | |||||
| 60 | pu blic int _ insertedSt atusValue; | |||||
| 61 | ||||||
| 62 | #e ndregion C lass Level Members | |||||
| 63 | ||||||
| 64 | #r egion How To Sample Code | |||||
| 65 | // / <summary > | |||||
| 66 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 67 | // / Create f ew types o f attribut es. | |||||
| 68 | // / Insert s tatus in t he existin g status l ist. | |||||
| 69 | // / Retrieve attribute . | |||||
| 70 | // / Update a ttribute. | |||||
| 71 | // / Update e xisting st ate value. | |||||
| 72 | // / Optional ly delete/ revert any attribute s | |||||
| 73 | // / that wer e created/ changed fo r this sam ple. | |||||
| 74 | / // </summa ry> | |||||
| 75 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 76 | // / <param n ame="promp tForDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 77 | // / created entities.< /param> | |||||
| 78 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 79 | { | |||||
| 80 | try | |||||
| 81 | { | |||||
| 82 | ||||||
| 83 | // C onnect to the Organi zation ser vice. | |||||
| 84 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 85 | 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 )) | |||||
| 86 | { | |||||
| 87 | // This st atement is required to enable early-boun d type sup port. | |||||
| 88 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 89 | ||||||
| 90 | //<snippet WorkWithAt tributes1> | |||||
| 91 | #region Ho w to creat e attribut es | |||||
| 92 | //<snippet WorkWithAt tributes2> | |||||
| 93 | // Create storage fo r new attr ibutes bei ng created | |||||
| 94 | addedAttri butes = ne w List<Att ributeMeta data>(); | |||||
| 95 | ||||||
| 96 | // Create a boolean attribute | |||||
| 97 | BooleanAtt ributeMeta data boolA ttribute = new Boole anAttribut eMetadata | |||||
| 98 | { | |||||
| 99 | // Set base prop erties | |||||
| 100 | Schema Name = "ne w_boolean" , | |||||
| 101 | Displa yName = ne w Label("S ample Bool ean", _lan guageCode) , | |||||
| 102 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 103 | Descri ption = ne w Label("B oolean Att ribute", _ languageCo de), | |||||
| 104 | // Set extended properties | |||||
| 105 | Option Set = new BooleanOpt ionSetMeta data( | |||||
| 106 | ne w OptionMe tadata(new Label("Tr ue", _lang uageCode), 1), | |||||
| 107 | ne w OptionMe tadata(new Label("Fa lse", _lan guageCode) , 0) | |||||
| 108 | ) | |||||
| 109 | }; | |||||
| 110 | ||||||
| 111 | // Add to list | |||||
| 112 | addedAttri butes.Add( boolAttrib ute); | |||||
| 113 | ||||||
| 114 | // Create a date tim e attribut e | |||||
| 115 | DateTimeAt tributeMet adata dtAt tribute = new DateTi meAttribut eMetadata | |||||
| 116 | { | |||||
| 117 | // Set base prop erties | |||||
| 118 | Schema Name = "ne w_datetime ", | |||||
| 119 | Displa yName = ne w Label("S ample Date Time", _la nguageCode ), | |||||
| 120 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 121 | Descri ption = ne w Label("D ateTime At tribute", _languageC ode), | |||||
| 122 | // Set extended properties | |||||
| 123 | Format = DateTim eFormat.Da teOnly, | |||||
| 124 | ImeMod e = ImeMod e.Disabled | |||||
| 125 | }; | |||||
| 126 | ||||||
| 127 | // Add to list | |||||
| 128 | addedAttri butes.Add( dtAttribut e); | |||||
| 129 | ||||||
| 130 | // Create a decimal attribute | |||||
| 131 | DecimalAtt ributeMeta data decim alAttribut e = new De cimalAttri buteMetada ta | |||||
| 132 | { | |||||
| 133 | // Set base prop erties | |||||
| 134 | Schema Name = "ne w_decimal" , | |||||
| 135 | Displa yName = ne w Label("S ample Deci mal", _lan guageCode) , | |||||
| 136 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 137 | Descri ption = ne w Label("D ecimal Att ribute", _ languageCo de), | |||||
| 138 | // Set extended properties | |||||
| 139 | MaxVal ue = 100, | |||||
| 140 | MinVal ue = 0, | |||||
| 141 | Precis ion = 1 | |||||
| 142 | }; | |||||
| 143 | ||||||
| 144 | // Add to list | |||||
| 145 | addedAttri butes.Add( decimalAtt ribute); | |||||
| 146 | ||||||
| 147 | // Create a integer attribute | |||||
| 148 | IntegerAtt ributeMeta data integ erAttribut e = new In tegerAttri buteMetada ta | |||||
| 149 | { | |||||
| 150 | // Set base prop erties | |||||
| 151 | Schema Name = "ne w_integer" , | |||||
| 152 | Displa yName = ne w Label("S ample Inte ger", _lan guageCode) , | |||||
| 153 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 154 | Descri ption = ne w Label("I nteger Att ribute", _ languageCo de), | |||||
| 155 | // Set extended properties | |||||
| 156 | Format = Integer Format.Non e, | |||||
| 157 | MaxVal ue = 100, | |||||
| 158 | MinVal ue = 0 | |||||
| 159 | }; | |||||
| 160 | ||||||
| 161 | // Add to list | |||||
| 162 | addedAttri butes.Add( integerAtt ribute); | |||||
| 163 | ||||||
| 164 | // Create a memo att ribute | |||||
| 165 | MemoAttrib uteMetadat a memoAttr ibute = ne w MemoAttr ibuteMetad ata | |||||
| 166 | { | |||||
| 167 | // Set base prop erties | |||||
| 168 | Schema Name = "ne w_memo", | |||||
| 169 | Displa yName = ne w Label("S ample Memo ", _langua geCode), | |||||
| 170 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 171 | Descri ption = ne w Label("M emo Attrib ute", _lan guageCode) , | |||||
| 172 | // Set extended properties | |||||
| 173 | Format = StringF ormat.Text Area, | |||||
| 174 | ImeMod e = ImeMod e.Disabled , | |||||
| 175 | MaxLen gth = 500 | |||||
| 176 | }; | |||||
| 177 | ||||||
| 178 | // Add to list | |||||
| 179 | addedAttri butes.Add( memoAttrib ute); | |||||
| 180 | ||||||
| 181 | // Create a money at tribute | |||||
| 182 | MoneyAttri buteMetada ta moneyAt tribute = new MoneyA ttributeMe tadata | |||||
| 183 | { | |||||
| 184 | // Set base prop erties | |||||
| 185 | Schema Name = "ne w_money", | |||||
| 186 | Displa yName = ne w Label("M oney Pickl ist", _lan guageCode) , | |||||
| 187 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 188 | Descri ption = ne w Label("M oney Attri bue", _lan guageCode) , | |||||
| 189 | // Set extended properties | |||||
| 190 | MaxVal ue = 1000. 00, | |||||
| 191 | MinVal ue = 0.00, | |||||
| 192 | Precis ion = 1, | |||||
| 193 | Precis ionSource = 1, | |||||
| 194 | ImeMod e = ImeMod e.Disabled | |||||
| 195 | }; | |||||
| 196 | ||||||
| 197 | // Add to list | |||||
| 198 | addedAttri butes.Add( moneyAttri bute); | |||||
| 199 | ||||||
| 200 | // Create a picklist attribute | |||||
| 201 | PicklistAt tributeMet adata pick ListAttrib ute = | |||||
| 202 | new Pi cklistAttr ibuteMetad ata | |||||
| 203 | { | |||||
| 204 | // Set base prop erties | |||||
| 205 | Schema Name = "ne w_picklist ", | |||||
| 206 | Displa yName = ne w Label("S ample Pick list", _la nguageCode ), | |||||
| 207 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 208 | Descri ption = ne w Label("P icklist At tribute", _languageC ode), | |||||
| 209 | // Set extended properties | |||||
| 210 | // Bui ld local p icklist op tions | |||||
| 211 | Option Set = new OptionSetM etadata | |||||
| 212 | { | |||||
| 213 | IsGlobal = false, | |||||
| 214 | OptionSe tType = Op tionSetTyp e.Picklist , | |||||
| 215 | Options = | |||||
| 216 | { | |||||
| 217 | new Opti onMetadata ( | |||||
| 218 | new Label("Cre ated", _la nguageCode ), null), | |||||
| 219 | new Opti onMetadata ( | |||||
| 220 | new Label("Upd ated", _la nguageCode ), null), | |||||
| 221 | new Opti onMetadata ( | |||||
| 222 | new Label("Del eted", _la nguageCode ), null) | |||||
| 223 | } | |||||
| 224 | } | |||||
| 225 | }; | |||||
| 226 | ||||||
| 227 | // Add to list | |||||
| 228 | addedAttri butes.Add( pickListAt tribute); | |||||
| 229 | ||||||
| 230 | // Create a string a ttribute | |||||
| 231 | StringAttr ibuteMetad ata string Attribute = new Stri ngAttribut eMetadata | |||||
| 232 | { | |||||
| 233 | // Set base prop erties | |||||
| 234 | Schema Name = "ne w_string", | |||||
| 235 | Displa yName = ne w Label("S ample Stri ng", _lang uageCode), | |||||
| 236 | Requir edLevel = new Attrib uteRequire dLevelMana gedPropert y(Attribut eRequiredL evel.None) , | |||||
| 237 | Descri ption = ne w Label("S tring Attr ibute", _l anguageCod e), | |||||
| 238 | // Set extended properties | |||||
| 239 | MaxLen gth = 100 | |||||
| 240 | }; | |||||
| 241 | ||||||
| 242 | // Add to list | |||||
| 243 | addedAttri butes.Add( stringAttr ibute); | |||||
| 244 | ||||||
| 245 | // NOTE: L ookupAttri buteMetada ta cannot be created outside t he context of a rela tionship. | |||||
| 246 | // Refer t o the Work WithRelati onships.cs reference SDK sampl e for an e xample of this attri bute type. | |||||
| 247 | ||||||
| 248 | // NOTE: S tateAttrib uteMetadat a and Stat usAttribut eMetadata cannot be created vi a the SDK. | |||||
| 249 | ||||||
| 250 | foreach (A ttributeMe tadata anA ttribute i n addedAtt ributes) | |||||
| 251 | { | |||||
| 252 | // Cre ate the re quest. | |||||
| 253 | Create AttributeR equest cre ateAttribu teRequest = new Crea teAttribut eRequest | |||||
| 254 | { | |||||
| 255 | En tityName = Contact.E ntityLogic alName, | |||||
| 256 | At tribute = anAttribut e | |||||
| 257 | }; | |||||
| 258 | ||||||
| 259 | // Exe cute the r equest. | |||||
| 260 | _servi ceProxy.Ex ecute(crea teAttribut eRequest); | |||||
| 261 | ||||||
| 262 | Consol e.WriteLin e("Created the attri bute {0}." , anAttrib ute.Schema Name); | |||||
| 263 | } | |||||
| 264 | //</snippe tWorkWithA ttributes2 > | |||||
| 265 | #endregion How to cr eate attri butes | |||||
| 266 | ||||||
| 267 | #region Ho w to inser t status | |||||
| 268 | //<snippet WorkWithAt tributes3> | |||||
| 269 | // Use Ins ertStatusV alueReques t message to insert a new stat us | |||||
| 270 | // in an e xisting st atus attri bute. | |||||
| 271 | // Create the reques t. | |||||
| 272 | InsertStat usValueReq uest inser tStatusVal ueRequest = | |||||
| 273 | new In sertStatus ValueReque st | |||||
| 274 | { | |||||
| 275 | Attrib uteLogical Name = "st atuscode", | |||||
| 276 | Entity LogicalNam e = Contac t.EntityLo gicalName, | |||||
| 277 | Label = new Labe l("Dormant ", _langua geCode), | |||||
| 278 | StateC ode = 0 | |||||
| 279 | }; | |||||
| 280 | ||||||
| 281 | // Execute the reque st and sto re newly i nserted va lue | |||||
| 282 | // for cle anup, used later par t of this sample. | |||||
| 283 | _insertedS tatusValue = ((Inser tStatusVal ueResponse )_serviceP roxy.Execu te( | |||||
| 284 | insert StatusValu eRequest)) .NewOption Value; | |||||
| 285 | ||||||
| 286 | Console.Wr iteLine("C reated {0} with the value of { 1}.", | |||||
| 287 | insert StatusValu eRequest.L abel.Local izedLabels [0].Label, | |||||
| 288 | _inser tedStatusV alue); | |||||
| 289 | //</snippe tWorkWithA ttributes3 > | |||||
| 290 | #endregion How to in sert statu s | |||||
| 291 | ||||||
| 292 | #region Ho w to retri eve attrib ute | |||||
| 293 | //<snippet WorkWithAt tributes4> | |||||
| 294 | // Create the reques t | |||||
| 295 | RetrieveAt tributeReq uest attri buteReques t = new Re trieveAttr ibuteReque st | |||||
| 296 | { | |||||
| 297 | Entity LogicalNam e = Contac t.EntityLo gicalName, | |||||
| 298 | Logica lName = "n ew_string" , | |||||
| 299 | Retrie veAsIfPubl ished = tr ue | |||||
| 300 | }; | |||||
| 301 | ||||||
| 302 | // Execute the reque st | |||||
| 303 | RetrieveAt tributeRes ponse attr ibuteRespo nse = | |||||
| 304 | (Retri eveAttribu teResponse )_serviceP roxy.Execu te(attribu teRequest) ; | |||||
| 305 | ||||||
| 306 | Console.Wr iteLine("R etrieved t he attribu te {0}.", | |||||
| 307 | attrib uteRespons e.Attribut eMetadata. SchemaName ); | |||||
| 308 | //</snippe tWorkWithA ttributes4 > | |||||
| 309 | #endregion How to re trieve att ribute | |||||
| 310 | ||||||
| 311 | #region Ho w to updat e attribut e | |||||
| 312 | //<snippet WorkWithAt tributes5> | |||||
| 313 | // Modify the retrie ved attrib ute | |||||
| 314 | AttributeM etadata re trievedAtt ributeMeta data = | |||||
| 315 | attrib uteRespons e.Attribut eMetadata; | |||||
| 316 | retrievedA ttributeMe tadata.Dis playName = | |||||
| 317 | new La bel("Updat e String A ttribute", _language Code); | |||||
| 318 | ||||||
| 319 | // Update an attribu te retriev ed via Ret rieveAttri buteReques t | |||||
| 320 | UpdateAttr ibuteReque st updateR equest = n ew UpdateA ttributeRe quest | |||||
| 321 | { | |||||
| 322 | Attrib ute = retr ievedAttri buteMetada ta, | |||||
| 323 | Entity Name = Con tact.Entit yLogicalNa me, | |||||
| 324 | MergeL abels = fa lse | |||||
| 325 | }; | |||||
| 326 | ||||||
| 327 | // Execute the reque st | |||||
| 328 | _servicePr oxy.Execut e(updateRe quest); | |||||
| 329 | ||||||
| 330 | Console.Wr iteLine("U pdated the attribute {0}.", | |||||
| 331 | retrie vedAttribu teMetadata .SchemaNam e); | |||||
| 332 | //</snippe tWorkWithA ttributes5 > | |||||
| 333 | #endregion How to up date attri bute | |||||
| 334 | ||||||
| 335 | #region Ho w to updat e state va lue | |||||
| 336 | //<snippet WorkWithAt tributes6> | |||||
| 337 | // Modify the state value labe l from Act ive to Ope n. | |||||
| 338 | // Create the reques t. | |||||
| 339 | UpdateStat eValueRequ est update StateValue = new Upd ateStateVa lueRequest | |||||
| 340 | { | |||||
| 341 | Attrib uteLogical Name = "st atecode", | |||||
| 342 | Entity LogicalNam e = Contac t.EntityLo gicalName, | |||||
| 343 | Value = 1, | |||||
| 344 | Label = new Labe l("Open", _languageC ode) | |||||
| 345 | }; | |||||
| 346 | ||||||
| 347 | // Execute the reque st. | |||||
| 348 | _servicePr oxy.Execut e(updateSt ateValue); | |||||
| 349 | ||||||
| 350 | Console.Wr iteLine( | |||||
| 351 | "Updat ed {0} sta te attribu te of {1} entity fro m 'Active' to '{2}'. ", | |||||
| 352 | update StateValue .Attribute LogicalNam e, | |||||
| 353 | update StateValue .EntityLog icalName, | |||||
| 354 | update StateValue .Label.Loc alizedLabe ls[0].Labe l | |||||
| 355 | ); | |||||
| 356 | //</snippe tWorkWithA ttributes6 > | |||||
| 357 | #endregion How to up date state value | |||||
| 358 | ||||||
| 359 | #region Ho w to inser t a new op tion item in a local option se t | |||||
| 360 | //<snippet WorkWithAt tributes7> | |||||
| 361 | // Create a request. | |||||
| 362 | InsertOpti onValueReq uest inser tOptionVal ueRequest = | |||||
| 363 | new In sertOption ValueReque st | |||||
| 364 | { | |||||
| 365 | Attrib uteLogical Name = "ne w_picklist ", | |||||
| 366 | Entity LogicalNam e = Contac t.EntityLo gicalName, | |||||
| 367 | Label = new Labe l("New Pic klist Labe l", _langu ageCode) | |||||
| 368 | }; | |||||
| 369 | ||||||
| 370 | // Execute the reque st. | |||||
| 371 | int insert OptionValu e = ((Inse rtOptionVa lueRespons e)_service Proxy.Exec ute( | |||||
| 372 | insert OptionValu eRequest)) .NewOption Value; | |||||
| 373 | ||||||
| 374 | Console.Wr iteLine("C reated {0} with the value of { 1}.", | |||||
| 375 | insert OptionValu eRequest.L abel.Local izedLabels [0].Label, | |||||
| 376 | insert OptionValu e); | |||||
| 377 | //</snippe tWorkWithA ttributes7 > | |||||
| 378 | #endregion How to in sert a new option it em in a lo cal option set | |||||
| 379 | ||||||
| 380 | #region Ho w to chang e the orde r of optio ns of a lo cal option set | |||||
| 381 | //<snippet WorkWithAt tributes8> | |||||
| 382 | // Use the RetrieveA ttributeRe quest mess age to ret rieve | |||||
| 383 | // a attri bute by it 's logical name. | |||||
| 384 | RetrieveAt tributeReq uest retri eveAttribu teRequest = | |||||
| 385 | new Re trieveAttr ibuteReque st | |||||
| 386 | { | |||||
| 387 | Entity LogicalNam e = Contac t.EntityLo gicalName, | |||||
| 388 | Logica lName = "n ew_picklis t", | |||||
| 389 | Retrie veAsIfPubl ished = tr ue | |||||
| 390 | }; | |||||
| 391 | ||||||
| 392 | // Execute the reque st. | |||||
| 393 | RetrieveAt tributeRes ponse retr ieveAttrib uteRespons e = | |||||
| 394 | (Retri eveAttribu teResponse )_serviceP roxy.Execu te( | |||||
| 395 | retrie veAttribut eRequest); | |||||
| 396 | ||||||
| 397 | // Access the retrie ved attrib ute. | |||||
| 398 | PicklistAt tributeMet adata retr ievedPickl istAttribu teMetadata = | |||||
| 399 | (Pickl istAttribu teMetadata ) | |||||
| 400 | retrie veAttribut eResponse. AttributeM etadata; | |||||
| 401 | ||||||
| 402 | // Get the current o ptions lis t for the retrieved attribute. | |||||
| 403 | OptionMeta data[] opt ionList = | |||||
| 404 | retrie vedPicklis tAttribute Metadata.O ptionSet.O ptions.ToA rray(); | |||||
| 405 | ||||||
| 406 | // Change the order of the ori ginal opti on's list. | |||||
| 407 | // Use the OrderBy ( OrderByDes cending) l inq functi on to sort options i n | |||||
| 408 | // ascendi ng (descen ding) orde r accordin g to label text. | |||||
| 409 | // For asc ending ord er use thi s: | |||||
| 410 | var update OptionList = | |||||
| 411 | option List.Order By(x => x. Label.Loca lizedLabel s[0].Label ).ToList() ; | |||||
| 412 | ||||||
| 413 | // For des cending or der use th is: | |||||
| 414 | // var upd ateOptionL ist = | |||||
| 415 | // op tionList.O rderByDesc ending( | |||||
| 416 | // x => x.Label .Localized Labels[0]. Label).ToL ist(); | |||||
| 417 | ||||||
| 418 | // Create the reques t. | |||||
| 419 | OrderOptio nRequest o rderOption Request = new OrderO ptionReque st | |||||
| 420 | { | |||||
| 421 | // Set the prope rties for the reques t. | |||||
| 422 | Attrib uteLogical Name = "ne w_picklist ", | |||||
| 423 | Entity LogicalNam e = Contac t.EntityLo gicalName, | |||||
| 424 | // Set the chang ed order u sing Selec t linq fun ction | |||||
| 425 | // to get only v alues in a n array fr om the cha nged optio n list. | |||||
| 426 | Values = updateO ptionList. Select(x = > x.Value. Value).ToA rray() | |||||
| 427 | }; | |||||
| 428 | ||||||
| 429 | // Execute the reque st | |||||
| 430 | _servicePr oxy.Execut e(orderOpt ionRequest ); | |||||
| 431 | ||||||
| 432 | Console.Wr iteLine("O ption Set option ord er changed "); | |||||
| 433 | //</snippe tWorkWithA ttributes8 > | |||||
| 434 | #endregion How to ch ange the o rder of op tions of a global op tion set | |||||
| 435 | ||||||
| 436 | // NOTE: A ll customi zations mu st be publ ished befo re they ca n be used. | |||||
| 437 | _servicePr oxy.Execut e(new Publ ishAllXmlR equest()); | |||||
| 438 | Console.Wr iteLine("P ublished a ll customi zations.") ; | |||||
| 439 | //</snippe tWorkWithA ttributes1 > | |||||
| 440 | ||||||
| 441 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 442 | } | |||||
| 443 | } | |||||
| 444 | ||||||
| 445 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 446 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 447 | { | |||||
| 448 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 449 | thro w; | |||||
| 450 | } | |||||
| 451 | } | |||||
| 452 | ||||||
| 453 | // / <summary > | |||||
| 454 | // / Deletes/ Reverts th e record t hat was cr eated/chan ged for th is sample. | |||||
| 455 | // / <param n ame="promp t">Indicat es whether to prompt the user to delete | |||||
| 456 | // / the reco rds create d in this sample.</p aram> | |||||
| 457 | // / </summar y> | |||||
| 458 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 459 | { | |||||
| 460 | bool del eteRecords = true; | |||||
| 461 | ||||||
| 462 | if (prom pt) | |||||
| 463 | { | |||||
| 464 | Cons ole.WriteL ine( | |||||
| 465 | "\nDo you want these entity re cords to b e deleted? (y/n)"); | |||||
| 466 | Stri ng answer = Console. ReadLine() ; | |||||
| 467 | ||||||
| 468 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 469 | } | |||||
| 470 | ||||||
| 471 | if (dele teRecords) | |||||
| 472 | { | |||||
| 473 | #reg ion How to delete at tribute | |||||
| 474 | //<s nippetWork WithAttrib utes9> | |||||
| 475 | // D elete all attributes created f or this sa mple. | |||||
| 476 | fore ach (Attri buteMetada ta anAttri bute in ad dedAttribu tes) | |||||
| 477 | { | |||||
| 478 | // Create the reques t object | |||||
| 479 | DeleteAttr ibuteReque st deleteA ttribute = new Delet eAttribute Request | |||||
| 480 | { | |||||
| 481 | // Set the reque st propert ies | |||||
| 482 | Entity LogicalNam e = Contac t.EntityLo gicalName, | |||||
| 483 | Logica lName = an Attribute. SchemaName | |||||
| 484 | }; | |||||
| 485 | // Execute the reque st | |||||
| 486 | _servicePr oxy.Execut e(deleteAt tribute); | |||||
| 487 | } | |||||
| 488 | //</ snippetWor kWithAttri butes9> | |||||
| 489 | #end region How to delete attribute | |||||
| 490 | ||||||
| 491 | #reg ion How to remove in serted sta tus value | |||||
| 492 | //<s nippetWork WithAttrib utes10> | |||||
| 493 | // D elete the newly inse rted statu s value. | |||||
| 494 | // C reate the request ob ject | |||||
| 495 | Dele teOptionVa lueRequest deleteReq uest = new DeleteOpt ionValueRe quest | |||||
| 496 | { | |||||
| 497 | AttributeL ogicalName = "status code", | |||||
| 498 | EntityLogi calName = Contact.En tityLogica lName, | |||||
| 499 | Value = _i nsertedSta tusValue | |||||
| 500 | }; | |||||
| 501 | ||||||
| 502 | // E xecute the request | |||||
| 503 | _ser viceProxy. Execute(de leteReques t); | |||||
| 504 | ||||||
| 505 | Cons ole.WriteL ine("Delet ed all att ributes cr eated for this sampl e."); | |||||
| 506 | //</ snippetWor kWithAttri butes10> | |||||
| 507 | #end region How to remove inserted status val ue | |||||
| 508 | ||||||
| 509 | #reg ion Revert the chang ed state v alue | |||||
| 510 | //<s nippetWork WithAttrib utes11> | |||||
| 511 | // R evert the state valu e label fr om Open to Active. | |||||
| 512 | // C reate the request. | |||||
| 513 | Upda teStateVal ueRequest revertStat eValue = n ew UpdateS tateValueR equest | |||||
| 514 | { | |||||
| 515 | AttributeL ogicalName = "statec ode", | |||||
| 516 | EntityLogi calName = Contact.En tityLogica lName, | |||||
| 517 | Value = 1, | |||||
| 518 | Label = ne w Label("A ctive", _l anguageCod e) | |||||
| 519 | }; | |||||
| 520 | ||||||
| 521 | // E xecute the request. | |||||
| 522 | _ser viceProxy. Execute(re vertStateV alue); | |||||
| 523 | ||||||
| 524 | // N OTE: All c ustomizati ons must b e publishe d before t hey can be used. | |||||
| 525 | _ser viceProxy. Execute(ne w PublishA llXmlReque st()); | |||||
| 526 | ||||||
| 527 | Cons ole.WriteL ine( | |||||
| 528 | "Reverted {0} state attribute of {1} ent ity from ' Open' to ' {2}'.", | |||||
| 529 | revertStat eValue.Att ributeLogi calName, | |||||
| 530 | revertStat eValue.Ent ityLogical Name, | |||||
| 531 | revertStat eValue.Lab el.Localiz edLabels[0 ].Label | |||||
| 532 | ); | |||||
| 533 | //</ snippetWor kWithAttri butes11> | |||||
| 534 | #end region Rev ert the ch anged stat e value | |||||
| 535 | } | |||||
| 536 | } | |||||
| 537 | #e ndregion H ow To Samp le Code | |||||
| 538 | ||||||
| 539 | #r egion Main | |||||
| 540 | // / <summary > | |||||
| 541 | // / Standard Main() me thod used by most SD K samples. | |||||
| 542 | // / </summar y> | |||||
| 543 | // / <param n ame="args" ></param> | |||||
| 544 | st atic publi c void Mai n(string[] args) | |||||
| 545 | { | |||||
| 546 | try | |||||
| 547 | { | |||||
| 548 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 549 | // c redentials from the user. | |||||
| 550 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 551 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 552 | ||||||
| 553 | Work WithAttrib utes app = new WorkW ithAttribu tes(); | |||||
| 554 | app. Run(config , true); | |||||
| 555 | } | |||||
| 556 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 557 | { | |||||
| 558 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 559 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 560 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 561 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 562 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 563 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 564 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 565 | } | |||||
| 566 | catch (S ystem.Time outExcepti on ex) | |||||
| 567 | { | |||||
| 568 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 569 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 570 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 571 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 572 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 573 | } | |||||
| 574 | catch (S ystem.Exce ption ex) | |||||
| 575 | { | |||||
| 576 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 577 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 578 | ||||||
| 579 | // D isplay the details o f the inne r exceptio n. | |||||
| 580 | if ( ex.InnerEx ception != null) | |||||
| 581 | { | |||||
| 582 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 583 | ||||||
| 584 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e | |||||
| 585 | = ex.I nnerExcept ion | |||||
| 586 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 587 | if (fe != null) | |||||
| 588 | { | |||||
| 589 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 590 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 591 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 592 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 593 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 594 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 595 | } | |||||
| 596 | } | |||||
| 597 | } | |||||
| 598 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 599 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 600 | ||||||
| 601 | finally | |||||
| 602 | { | |||||
| 603 | ||||||
| 604 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 605 | Cons ole.ReadLi ne(); | |||||
| 606 | } | |||||
| 607 | ||||||
| 608 | } | |||||
| 609 | #e ndregion M ain | |||||
| 610 | ||||||
| 611 | } | |||||
| 612 | } | |||||
| 613 | //</snippe tWorkWithA ttributes> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.