Produced by Araxis Merge on 2/1/2017 2:56:55 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\VisualizationsAndDashboards | AssignDashboardToUser.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:55 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 383 |
| 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 | // | |||||
| 4 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 5 | // | |||||
| 6 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 7 | // | |||||
| 8 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 9 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 10 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 11 | // | |||||
| 12 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 13 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 14 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 15 | // PARTIC ULAR PURPO SE. | |||||
| 16 | // | |||||
| 17 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 18 | //<snippet AssignDash boardToUse r> | |||||
| 19 | using Syst em; | |||||
| 20 | using Syst em.Linq; | |||||
| 21 | using Syst em.Service Model; | |||||
| 22 | using Syst em.Service Model.Desc ription; | |||||
| 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 Syst em.Xml.Lin q; | |||||
| 27 | using Micr osoft.Xrm. Sdk; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 30 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 31 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 32 | // found i n the SDK\ bin folder . | |||||
| 33 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 34 | ||||||
| 35 | using Syst em.Directo ryServices ; | |||||
| 36 | using Syst em.Threadi ng; | |||||
| 37 | ||||||
| 38 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 39 | { | |||||
| 40 | public class Ass ignDashboa rdToUser | |||||
| 41 | { | |||||
| 42 | #r egion Clas s Level Me mbers | |||||
| 43 | ||||||
| 44 | // / <summary > | |||||
| 45 | // / Stores t he organiz ation serv ice proxy. | |||||
| 46 | // / </summar y> | |||||
| 47 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 48 | ||||||
| 49 | // Define th e IDs need ed for thi s sample. | |||||
| 50 | pr ivate Guid _userDash boardId; | |||||
| 51 | pr ivate Guid _otherUse rId; | |||||
| 52 | ||||||
| 53 | #e ndregion C lass Level Members | |||||
| 54 | ||||||
| 55 | #r egion How To Sample Code | |||||
| 56 | // / <summary > | |||||
| 57 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, | |||||
| 58 | // / a user d ashbaord i s assigned to anothe r user. | |||||
| 59 | // / </summar y> | |||||
| 60 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 61 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 62 | // / created entities.< /param> | |||||
| 63 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 64 | { | |||||
| 65 | try | |||||
| 66 | { | |||||
| 67 | ||||||
| 68 | // C onnect to the Organi zation ser vice. | |||||
| 69 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 70 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, | |||||
| 71 | s erverConfi g.Credenti als, serve rConfig.De viceCreden tials)) | |||||
| 72 | { | |||||
| 73 | // This st atement is required to enable early-boun d type sup port. | |||||
| 74 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 75 | ||||||
| 76 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 77 | CreateRequ iredRecord s(); | |||||
| 78 | ||||||
| 79 | //<snippet AssignDash boardToUse r1> | |||||
| 80 | AssignRequ est assign Request = new Assign Request | |||||
| 81 | { | |||||
| 82 | Assign ee = new E ntityRefer ence | |||||
| 83 | { | |||||
| 84 | Lo gicalName = SystemUs er.EntityL ogicalName , | |||||
| 85 | // Here we c ould assig n the visu alization to the new ly created user | |||||
| 86 | Id = _otherU serId | |||||
| 87 | }, | |||||
| 88 | ||||||
| 89 | Target = new Ent ityReferen ce | |||||
| 90 | { | |||||
| 91 | Lo gicalName = UserForm .EntityLog icalName, | |||||
| 92 | Id = _userDa shboardId | |||||
| 93 | } | |||||
| 94 | }; | |||||
| 95 | _servicePr oxy.Execut e(assignRe quest); | |||||
| 96 | ||||||
| 97 | Console.Wr iteLine("T he user da shboard ha s been ass igned to K evin Cook. "); | |||||
| 98 | ||||||
| 99 | //</snippe tAssignDas hboardToUs er1> | |||||
| 100 | ||||||
| 101 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 102 | } | |||||
| 103 | } | |||||
| 104 | ||||||
| 105 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 106 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 107 | { | |||||
| 108 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 109 | thro w; | |||||
| 110 | } | |||||
| 111 | } | |||||
| 112 | ||||||
| 113 | // / <summary > | |||||
| 114 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 115 | // / Creates the dashbo ard. | |||||
| 116 | // / </summar y> | |||||
| 117 | pu blic void CreateRequ iredRecord s() | |||||
| 118 | { | |||||
| 119 | //Grab t he default public vi ew for opp ortunities . | |||||
| 120 | QueryExp ression my SavedQuery = new Que ryExpressi on | |||||
| 121 | { | |||||
| 122 | Colu mnSet = ne w ColumnSe t("savedqu eryid"), | |||||
| 123 | Enti tyName = S avedQuery. EntityLogi calName, | |||||
| 124 | Crit eria = new FilterExp ression | |||||
| 125 | { | |||||
| 126 | Conditions = | |||||
| 127 | { | |||||
| 128 | ne w Conditio nExpressio n | |||||
| 129 | { | |||||
| 130 | Attribut eName = "i sdefault", | |||||
| 131 | Operator = Conditi onOperator .Equal, | |||||
| 132 | Values = {true} | |||||
| 133 | }, | |||||
| 134 | ne w Conditio nExpressio n | |||||
| 135 | { | |||||
| 136 | Attribut eName = "q uerytype", | |||||
| 137 | Operator = Conditi onOperator .Equal, | |||||
| 138 | Values = {0} | |||||
| 139 | }, | |||||
| 140 | ne w Conditio nExpressio n | |||||
| 141 | { | |||||
| 142 | Attribut eName = "r eturnedtyp ecode", | |||||
| 143 | Operator = Conditi onOperator .Equal, | |||||
| 144 | Values = {Opportun ity.Entity TypeCode} | |||||
| 145 | } | |||||
| 146 | } | |||||
| 147 | } | |||||
| 148 | }; | |||||
| 149 | ||||||
| 150 | //This q uery shoul d return o ne and onl y one resu lt. | |||||
| 151 | SavedQue ry default Opportunit yQuery = _ servicePro xy.Retriev eMultiple( mySavedQue ry) | |||||
| 152 | .Ent ities.Sele ct(x => (S avedQuery) x).FirstOr Default(); | |||||
| 153 | ||||||
| 154 | // Retri eve visual izations o ut of the system. | |||||
| 155 | // This sample ass umes that you have t he "Top Op portunitie s" | |||||
| 156 | // visua lization t hat is ins talled wit h Microsof t Dynamics CRM. | |||||
| 157 | QueryByA ttribute v isualizati onQuery = new QueryB yAttribute | |||||
| 158 | { | |||||
| 159 | Enti tyName = S avedQueryV isualizati on.EntityL ogicalName , | |||||
| 160 | Colu mnSet = ne w ColumnSe t("savedqu eryvisuali zationid") , | |||||
| 161 | Attr ibutes = { "name" }, | |||||
| 162 | //If you do no t have thi s visualiz ation, you will need to change | |||||
| 163 | //th is line. | |||||
| 164 | Valu es = { "To p Opportun ities" } | |||||
| 165 | }; | |||||
| 166 | ||||||
| 167 | ||||||
| 168 | SavedQue ryVisualiz ation visu alization = _service Proxy.Retr ieveMultip le(visuali zationQuer y). | |||||
| 169 | Enti ties.Selec t(x => (Sa vedQueryVi sualizatio n)x).First OrDefault( ); | |||||
| 170 | ||||||
| 171 | //This i s the lang uage code for U.S. E nglish. If you are r unning thi s code | |||||
| 172 | //in a d ifferent l ocale, you will need to modify this valu e. | |||||
| 173 | int lang uageCode = 1033; | |||||
| 174 | ||||||
| 175 | //We set up our da shboard an d specify the FormXm l. Refer t o the | |||||
| 176 | //FormXm l schema i n the Micr osoft Dyna mics CRM S DK for mor e informat ion. | |||||
| 177 | UserForm dashboard = new Use rForm | |||||
| 178 | { | |||||
| 179 | Name = "Sample User Dash board", | |||||
| 180 | Desc ription = "Sample us er-owned d ashboard." , | |||||
| 181 | Form Xml = Stri ng.Format( @"<form> | |||||
| 182 | <tabs> | |||||
| 183 | <tab name='Tes t Dashboar d' vertica llayout='t rue'> | |||||
| 184 | <labels> | |||||
| 185 | <label descripti on='Sample User Dash board' lan guagecode= '{0}' /> | |||||
| 186 | </labels> | |||||
| 187 | <columns> | |||||
| 188 | <colum n width='1 00%'> | |||||
| 189 | <s ections> | |||||
| 190 | <section name='Inf ormation S ection' | |||||
| 191 | show label='fal se' showba r='false' | |||||
| 192 | colu mns='111'> | |||||
| 193 | <lab els> | |||||
| 194 | <label des cription=' Informatio n Section' | |||||
| 195 | langua gecode='{0 }' /> | |||||
| 196 | </la bels> | |||||
| 197 | <row s> | |||||
| 198 | <row> | |||||
| 199 | <cell colspan='1 ' rowspan= '10' | |||||
| 200 | sh owlabel='f alse'> | |||||
| 201 | <l abels> | |||||
| 202 | <label d escription ='Top Oppo rtunities - 1' | |||||
| 203 | language code='{0}' /> | |||||
| 204 | </ labels> | |||||
| 205 | <c ontrol id= 'Top10Oppo rtunities' | |||||
| 206 | classid= '{{E7A8127 8-8635-4d9 e-8D4D-594 80B391C5B} }'> | |||||
| 207 | <paramet ers> | |||||
| 208 | <Vie wId>{1}</V iewId> | |||||
| 209 | <IsU serView>fa lse</IsUse rView> | |||||
| 210 | <Rel ationshipN ame /> | |||||
| 211 | <Tar getEntityT ype>opport unity</Tar getEntityT ype> | |||||
| 212 | <Aut oExpand>Fi xed</AutoE xpand> | |||||
| 213 | <Ena bleQuickFi nd>false</ EnableQuic kFind> | |||||
| 214 | <Ena bleViewPic ker>false< /EnableVie wPicker> | |||||
| 215 | <Ena bleJumpBar >false</En ableJumpBa r> | |||||
| 216 | <Cha rtGridMode >Chart</Ch artGridMod e> | |||||
| 217 | <Vis ualization Id>{2}</Vi sualizatio nId> | |||||
| 218 | <Ena bleChartPi cker>false </EnableCh artPicker> | |||||
| 219 | <Rec ordsPerPag e>10</Reco rdsPerPage > | |||||
| 220 | </parame ters> | |||||
| 221 | </ control> | |||||
| 222 | </cell > | |||||
| 223 | <cell colspan='1 ' rowspan= '10' | |||||
| 224 | sh owlabel='f alse'> | |||||
| 225 | <l abels> | |||||
| 226 | <label d escription ='Top Oppo rtunities - 2' | |||||
| 227 | language code='{0}' /> | |||||
| 228 | </ labels> | |||||
| 229 | <c ontrol id= 'Top10Oppo rtunities2 ' | |||||
| 230 | classid= '{{E7A8127 8-8635-4d9 e-8D4D-594 80B391C5B} }'> | |||||
| 231 | <paramet ers> | |||||
| 232 | <Vie wId>{1}</V iewId> | |||||
| 233 | <IsU serView>fa lse</IsUse rView> | |||||
| 234 | <Rel ationshipN ame /> | |||||
| 235 | <Tar getEntityT ype>opport unity</Tar getEntityT ype> | |||||
| 236 | <Aut oExpand>Fi xed</AutoE xpand> | |||||
| 237 | <Ena bleQuickFi nd>false</ EnableQuic kFind> | |||||
| 238 | <Ena bleViewPic ker>false< /EnableVie wPicker> | |||||
| 239 | <Ena bleJumpBar >false</En ableJumpBa r> | |||||
| 240 | <Cha rtGridMode >Grid</Cha rtGridMode > | |||||
| 241 | <Vis ualization Id>{2}</Vi sualizatio nId> | |||||
| 242 | <Ena bleChartPi cker>false </EnableCh artPicker> | |||||
| 243 | <Rec ordsPerPag e>10</Reco rdsPerPage > | |||||
| 244 | </parame ters> | |||||
| 245 | </ control> | |||||
| 246 | </cell > | |||||
| 247 | </row> | |||||
| 248 | <row /> | |||||
| 249 | <row /> | |||||
| 250 | <row /> | |||||
| 251 | <row /> | |||||
| 252 | <row /> | |||||
| 253 | <row /> | |||||
| 254 | <row /> | |||||
| 255 | <row /> | |||||
| 256 | <row /> | |||||
| 257 | </ro ws> | |||||
| 258 | </sectio n> | |||||
| 259 | </ sections> | |||||
| 260 | </colu mn> | |||||
| 261 | </columns> | |||||
| 262 | </ta b> | |||||
| 263 | </tabs> | |||||
| 264 | </ form>", | |||||
| 265 | lang uageCode, | |||||
| 266 | defa ultOpportu nityQuery. SavedQuery Id.Value.T oString("B "), | |||||
| 267 | visu alization. SavedQuery Visualizat ionId.Valu e.ToString ("B")) | |||||
| 268 | }; | |||||
| 269 | _userDas hboardId = _serviceP roxy.Creat e(dashboar d); | |||||
| 270 | ||||||
| 271 | Console. WriteLine( "Created { 0}.", dash board.Name ); | |||||
| 272 | ||||||
| 273 | // Creat e another user to wh om the das hboard wil l be assig ned. | |||||
| 274 | _otherUs erId = Sys temUserPro vider.Retr ieveSalesM anager(_se rviceProxy ); | |||||
| 275 | } | |||||
| 276 | ||||||
| 277 | ||||||
| 278 | // / <summary > | |||||
| 279 | // / Deletes the entity record th at was cre ated for t his sample . | |||||
| 280 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 281 | // / to delet e the enti ty created in this s ample.</pa ram> | |||||
| 282 | // / The syst em user na med "Kevin Cook" tha t was crea ted by thi s sample w ill | |||||
| 283 | // / continue to exist on your sy stem becau se system users cann ot be dele ted | |||||
| 284 | // / in Micro soft Dynam ics CRM. T hey can on ly be enab led or dis abled. | |||||
| 285 | ||||||
| 286 | // / </summar y> | |||||
| 287 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 288 | { | |||||
| 289 | if (!pro mpt) retur n; | |||||
| 290 | ||||||
| 291 | // Ask t he user if the creat ed entitie s should b e deleted. | |||||
| 292 | Console. Write("\nD o you want these ent ity record s deleted? (y/n) [y] : "); | |||||
| 293 | String a nswer = Co nsole.Read Line(); | |||||
| 294 | ||||||
| 295 | if (answ er.StartsW ith("y") | | answer.S tartsWith( "Y") || an swer == St ring.Empty ) | |||||
| 296 | { | |||||
| 297 | // D elete acti on doesn't work on t he UserFor m instance if it is assigned | |||||
| 298 | // t o a user o ther than current us er. | |||||
| 299 | // S o as a wor karound, w e are impe rsonating the actual owner of | |||||
| 300 | // t he UserFor m instance to comple te the del ete action . | |||||
| 301 | // T o imperson ate anothe r user, se t the Orga nizationSe rviceProxy .CallerId | |||||
| 302 | // p roperty to the ID of the other user. | |||||
| 303 | _ser viceProxy. CallerId = _otherUse rId; | |||||
| 304 | ||||||
| 305 | _ser viceProxy. Delete(Use rForm.Enti tyLogicalN ame, _user DashboardI d); | |||||
| 306 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 307 | } | |||||
| 308 | } | |||||
| 309 | ||||||
| 310 | #e ndregion H ow To Samp le Code | |||||
| 311 | ||||||
| 312 | #r egion Main | |||||
| 313 | // / <summary > | |||||
| 314 | // / Main. Ru ns the sam ple and pr ovides err or output. | |||||
| 315 | // / <param n ame="args" >Array of arguments to Main me thod.</par am> | |||||
| 316 | // / </summar y> | |||||
| 317 | st atic publi c void Mai n(string[] args) | |||||
| 318 | { | |||||
| 319 | ||||||
| 320 | try | |||||
| 321 | { | |||||
| 322 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 323 | // c redentials from the user. | |||||
| 324 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 325 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 326 | ||||||
| 327 | Assi gnDashboar dToUser ap p = new As signDashbo ardToUser( ); | |||||
| 328 | app. Run(config , true); | |||||
| 329 | } | |||||
| 330 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 331 | { | |||||
| 332 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 333 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 334 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 335 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 336 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 337 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 338 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 339 | } | |||||
| 340 | catch (S ystem.Time outExcepti on ex) | |||||
| 341 | { | |||||
| 342 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 343 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 344 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 345 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 346 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 347 | } | |||||
| 348 | catch (S ystem.Exce ption ex) | |||||
| 349 | { | |||||
| 350 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 351 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 352 | ||||||
| 353 | // D isplay the details o f the inne r exceptio n. | |||||
| 354 | if ( ex.InnerEx ception != null) | |||||
| 355 | { | |||||
| 356 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 357 | ||||||
| 358 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = | |||||
| 359 | ex.Inn erExceptio n | |||||
| 360 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 361 | if (fe != null) | |||||
| 362 | { | |||||
| 363 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 364 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 365 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 366 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 367 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 368 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 369 | } | |||||
| 370 | } | |||||
| 371 | } | |||||
| 372 | finally | |||||
| 373 | { | |||||
| 374 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 375 | Cons ole.ReadLi ne(); | |||||
| 376 | } | |||||
| 377 | ||||||
| 378 | } | |||||
| 379 | #e ndregion M ain | |||||
| 380 | ||||||
| 381 | } | |||||
| 382 | } | |||||
| 383 | //</snippe tAssignDas hboardToUs er> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.