Produced by Araxis Merge on 2/1/2017 2:56:24 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\Goals | RollupAllGoalsForFiscalPeriodAndStretchedTargetRevenue.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:24 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 552 |
| 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 RollupAllG oalsForFis calPeriodA ndStretche dTargetRev enue> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Collect ions.Gener ic; | |||||
| 20 | ||||||
| 21 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 22 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 23 | using Micr osoft.Xrm. Sdk; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 26 | ||||||
| 27 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 28 | // found i n the SDK\ bin folder . | |||||
| 29 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 30 | ||||||
| 31 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 32 | { | |||||
| 33 | /// <s ummary> | |||||
| 34 | /// De monstrates how to wo rk with fi scal perio d goals th at utilize stretched | |||||
| 35 | /// ta rgets. | |||||
| 36 | /// </ summary> | |||||
| 37 | /// <r emarks> | |||||
| 38 | /// At run-time, you will be given t he option to delete all the | |||||
| 39 | /// da tabase rec ords creat ed by this program.< /remarks> | |||||
| 40 | public class Rol lupAllGoal sForFiscal PeriodAndS tretchedTa rgetRevenu e | |||||
| 41 | { | |||||
| 42 | #r egion Clas s Level Me mbers | |||||
| 43 | ||||||
| 44 | pr ivate Guid _salesMan agerId; | |||||
| 45 | pr ivate Guid _accountI d; | |||||
| 46 | pr ivate Guid _phoneCal lId; | |||||
| 47 | pr ivate Guid _phoneCal l2Id; | |||||
| 48 | pr ivate Guid _metricId ; | |||||
| 49 | pr ivate Guid _actualId ; | |||||
| 50 | pr ivate Guid _parentGo alId; | |||||
| 51 | pr ivate Guid _firstChi ldGoalId; | |||||
| 52 | pr ivate Guid _secondCh ildGoalId; | |||||
| 53 | pr ivate List <Guid> _ro llupQueryI ds = new L ist<Guid>( ); | |||||
| 54 | pr ivate List <Guid> _sa lesReprese ntativeIds = new Lis t<Guid>(); | |||||
| 55 | ||||||
| 56 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 57 | ||||||
| 58 | #e ndregion C lass Level Members | |||||
| 59 | ||||||
| 60 | #r egion How To Sample Code | |||||
| 61 | // / <summary > | |||||
| 62 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, the | |||||
| 63 | // / sample c reates a g oal and ch ild goals for a part icular fis cal period . | |||||
| 64 | // / Stretche d targets are tracke d as well. | |||||
| 65 | // / </summar y> | |||||
| 66 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 67 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 68 | // / created entities.< /param> | |||||
| 69 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 70 | { | |||||
| 71 | try | |||||
| 72 | { | |||||
| 73 | //<s nippetRoll upAllGoals ForFiscalP eriodAndSt retchedTar getRevenue 1> | |||||
| 74 | // C onnect to the Organi zation ser vice. | |||||
| 75 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 76 | 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 )) | |||||
| 77 | { | |||||
| 78 | // This st atement is required to enable early-boun d type sup port. | |||||
| 79 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 80 | ||||||
| 81 | CreateRequ iredRecord s(); | |||||
| 82 | ||||||
| 83 | #region Cr eate goal metric | |||||
| 84 | ||||||
| 85 | // Create the metric , setting the Metric Type to ' Count' and enabling | |||||
| 86 | // stretch tracking. | |||||
| 87 | Metric met ric = new Metric() | |||||
| 88 | { | |||||
| 89 | Name = "Sample C ount Metri c", | |||||
| 90 | IsAmou nt = false , | |||||
| 91 | IsStre tchTracked = true | |||||
| 92 | }; | |||||
| 93 | _metricId = _service Proxy.Crea te(metric) ; | |||||
| 94 | metric.Id = _metricI d; | |||||
| 95 | ||||||
| 96 | Console.Wr ite("Creat ed count m etric, "); | |||||
| 97 | ||||||
| 98 | #endregion | |||||
| 99 | ||||||
| 100 | #region Cr eate Rollu pFields | |||||
| 101 | ||||||
| 102 | // Create RollupFiel d which ta rgets comp leted (rec eived) pho ne calls. | |||||
| 103 | RollupFiel d actual = new Rollu pField() | |||||
| 104 | { | |||||
| 105 | Source Entity = P honeCall.E ntityLogic alName, | |||||
| 106 | GoalAt tribute = "actualint eger", | |||||
| 107 | Source State = 1, | |||||
| 108 | Source Status = 4 , | |||||
| 109 | Entity ForDateAtt ribute = P honeCall.E ntityLogic alName, | |||||
| 110 | DateAt tribute = "actualend ", | |||||
| 111 | Metric Id = metri c.ToEntity Reference( ) | |||||
| 112 | }; | |||||
| 113 | _actualId = _service Proxy.Crea te(actual) ; | |||||
| 114 | ||||||
| 115 | Console.Wr ite("creat ed complet ed phone c all Rollup Field, "); | |||||
| 116 | ||||||
| 117 | #endregion | |||||
| 118 | ||||||
| 119 | #region Cr eate the g oal rollup queries | |||||
| 120 | ||||||
| 121 | // Note: F ormatting the FetchX ml onto mu ltiple lin es in the following | |||||
| 122 | // rollup queries ca uses the l ength prop erty to be greater t han 1,000 | |||||
| 123 | // chars a nd will ca use an exc eption. | |||||
| 124 | ||||||
| 125 | // The fol lowing que ry locates closed in coming pho ne calls. | |||||
| 126 | GoalRollup Query goal RollupQuer y = new Go alRollupQu ery() | |||||
| 127 | { | |||||
| 128 | Name = "Example Goal Rollu p Query", | |||||
| 129 | QueryE ntityType = PhoneCal l.EntityLo gicalName, | |||||
| 130 | FetchX ml = @"<fe tch versio n='1.0' ou tput-forma t='xml-pla tform' map ping='logi cal' disti nct='false '><entity name='phon ecall'><at tribute na me='subjec t'/><attri bute name= 'statecode '/><attrib ute name=' priorityco de'/><attr ibute name ='schedule dend'/><at tribute na me='create dby'/><att ribute nam e='regardi ngobjectid '/><attrib ute name=' activityid '/><order attribute= 'subject' descending ='false'/> <filter ty pe='and'>< condition attribute= 'direction code' oper ator='eq' value='0'/ ><conditio n attribut e='stateco de' operat or='eq' va lue='1' /> </filter>< /entity></ fetch>" | |||||
| 131 | }; | |||||
| 132 | _rollupQue ryIds.Add( _servicePr oxy.Create (goalRollu pQuery)); | |||||
| 133 | goalRollup Query.Id = _rollupQu eryIds[0]; | |||||
| 134 | ||||||
| 135 | // The fol lowing que ry locates closed ou tgoing pho ne calls. | |||||
| 136 | GoalRollup Query goal RollupQuer y2 = new G oalRollupQ uery() | |||||
| 137 | { | |||||
| 138 | Name = "Example Goal Rollu p Query", | |||||
| 139 | QueryE ntityType = PhoneCal l.EntityLo gicalName, | |||||
| 140 | FetchX ml = @"<fe tch versio n='1.0' ou tput-forma t='xml-pla tform' map ping='logi cal' disti nct='false '><entity name='phon ecall'><at tribute na me='subjec t'/><attri bute name= 'statecode '/><attrib ute name=' priorityco de'/><attr ibute name ='schedule dend'/><at tribute na me='create dby'/><att ribute nam e='regardi ngobjectid '/><attrib ute name=' activityid '/><order attribute= 'subject' descending ='false'/> <filter ty pe='and'>< condition attribute= 'direction code' oper ator='eq' value='1'/ ><conditio n attribut e='stateco de' operat or='eq' va lue='1' /> </filter>< /entity></ fetch>" | |||||
| 141 | }; | |||||
| 142 | _rollupQue ryIds.Add( _servicePr oxy.Create (goalRollu pQuery2)); | |||||
| 143 | goalRollup Query2.Id = _rollupQ ueryIds[1] ; | |||||
| 144 | ||||||
| 145 | Console.Wr ite("creat ed rollup queries fo r phone ca lls.\n"); | |||||
| 146 | Console.Wr iteLine(); | |||||
| 147 | ||||||
| 148 | #endregion | |||||
| 149 | ||||||
| 150 | #region Cr eate goals | |||||
| 151 | ||||||
| 152 | // Determi ne current fiscal pe riod and y ear. | |||||
| 153 | // Note: T his sample assumes q uarterly f iscal peri ods. | |||||
| 154 | DateTime d ate = Date Time.Now; | |||||
| 155 | int quarte rNumber = (date.Mont h - 1) / 3 + 1; | |||||
| 156 | int yearNu mber = dat e.Year; | |||||
| 157 | ||||||
| 158 | // Create three goal s: one par ent goal a nd two chi ld goals. | |||||
| 159 | Goal paren tGoal = ne w Goal() | |||||
| 160 | { | |||||
| 161 | Title = "Parent Goal Examp le", | |||||
| 162 | Rollup OnlyFromCh ildGoals = true, | |||||
| 163 | Consid erOnlyGoal OwnersReco rds = true , | |||||
| 164 | Target Integer = 8, | |||||
| 165 | Stretc hTargetInt eger = 10, | |||||
| 166 | IsFisc alPeriodGo al = true, | |||||
| 167 | Fiscal Period = n ew OptionS etValue(qu arterNumbe r), | |||||
| 168 | Fiscal Year = new OptionSet Value(year Number), | |||||
| 169 | Metric Id = metri c.ToEntity Reference( ), | |||||
| 170 | GoalOw nerId = ne w EntityRe ference | |||||
| 171 | { | |||||
| 172 | Id = _salesM anagerId, | |||||
| 173 | Lo gicalName = SystemUs er.EntityL ogicalName | |||||
| 174 | }, | |||||
| 175 | OwnerI d = new En tityRefere nce | |||||
| 176 | { | |||||
| 177 | Id = _salesM anagerId, | |||||
| 178 | Lo gicalName = SystemUs er.EntityL ogicalName | |||||
| 179 | } | |||||
| 180 | }; | |||||
| 181 | _parentGoa lId = _ser viceProxy. Create(par entGoal); | |||||
| 182 | parentGoal .Id = _par entGoalId; | |||||
| 183 | ||||||
| 184 | Console.Wr iteLine("C reated par ent goal") ; | |||||
| 185 | Console.Wr iteLine("- ---------- --------") ; | |||||
| 186 | Console.Wr iteLine("T arget: {0} ", parentG oal.Target Integer.Va lue); | |||||
| 187 | Console.Wr iteLine("S tretch Tar get: {0}", | |||||
| 188 | parent Goal.Stret chTargetIn teger.Valu e); | |||||
| 189 | Console.Wr iteLine("G oal owner: {0}", par entGoal.Go alOwnerId. Id); | |||||
| 190 | Console.Wr iteLine("G oal Fiscal Period: { 0}", | |||||
| 191 | parent Goal.Fisca lPeriod.Va lue); | |||||
| 192 | Console.Wr iteLine("G oal Fiscal Year: {0} ", | |||||
| 193 | parent Goal.Fisca lYear.Valu e); | |||||
| 194 | Console.Wr iteLine("< End of Lis ting>"); | |||||
| 195 | Console.Wr iteLine(); | |||||
| 196 | ||||||
| 197 | Goal first ChildGoal = new Goal () | |||||
| 198 | { | |||||
| 199 | Title = "First C hild Goal Example", | |||||
| 200 | Consid erOnlyGoal OwnersReco rds = true , | |||||
| 201 | Target Integer = 5, | |||||
| 202 | Stretc hTargetInt eger = 6, | |||||
| 203 | IsFisc alPeriodGo al = true, | |||||
| 204 | Fiscal Period = n ew OptionS etValue(qu arterNumbe r), | |||||
| 205 | Fiscal Year = new OptionSet Value(year Number), | |||||
| 206 | Metric Id = metri c.ToEntity Reference( ), | |||||
| 207 | Parent GoalId = p arentGoal. ToEntityRe ference(), | |||||
| 208 | GoalOw nerId = ne w EntityRe ference | |||||
| 209 | { | |||||
| 210 | Id = _salesR epresentat iveIds[0], | |||||
| 211 | Lo gicalName = SystemUs er.EntityL ogicalName | |||||
| 212 | }, | |||||
| 213 | OwnerI d = new En tityRefere nce | |||||
| 214 | { | |||||
| 215 | Id = _salesM anagerId, | |||||
| 216 | Lo gicalName = SystemUs er.EntityL ogicalName | |||||
| 217 | }, | |||||
| 218 | Rollup QueryActua lIntegerId = goalRol lupQuery.T oEntityRef erence() | |||||
| 219 | }; | |||||
| 220 | _firstChil dGoalId = _servicePr oxy.Create (firstChil dGoal); | |||||
| 221 | ||||||
| 222 | Console.Wr iteLine("F irst child goal"); | |||||
| 223 | Console.Wr iteLine("- ---------- -----"); | |||||
| 224 | Console.Wr iteLine("T arget: {0} ", firstCh ildGoal.Ta rgetIntege r.Value); | |||||
| 225 | Console.Wr iteLine("S tretch Tar get: {0}", | |||||
| 226 | firstC hildGoal.S tretchTarg etInteger. Value); | |||||
| 227 | Console.Wr iteLine("G oal owner: {0}", fir stChildGoa l.GoalOwne rId.Id); | |||||
| 228 | Console.Wr iteLine("G oal Fiscal Period: { 0}", | |||||
| 229 | firstC hildGoal.F iscalPerio d.Value); | |||||
| 230 | Console.Wr iteLine("G oal Fiscal Year: {0} ", | |||||
| 231 | firstC hildGoal.F iscalYear. Value); | |||||
| 232 | Console.Wr iteLine(); | |||||
| 233 | ||||||
| 234 | Goal secon dChildGoal = new Goa l() | |||||
| 235 | { | |||||
| 236 | Title = "Second Child Goal Example", | |||||
| 237 | Consid erOnlyGoal OwnersReco rds = true , | |||||
| 238 | Target Integer = 3, | |||||
| 239 | Stretc hTargetInt eger = 4, | |||||
| 240 | IsFisc alPeriodGo al = true, | |||||
| 241 | Fiscal Period = n ew OptionS etValue(qu arterNumbe r), | |||||
| 242 | Fiscal Year = new OptionSet Value(year Number), | |||||
| 243 | Metric Id = metri c.ToEntity Reference( ), | |||||
| 244 | Parent GoalId = p arentGoal. ToEntityRe ference(), | |||||
| 245 | GoalOw nerId = ne w EntityRe ference | |||||
| 246 | { | |||||
| 247 | Id = _salesR epresentat iveIds[1], | |||||
| 248 | Lo gicalName = SystemUs er.EntityL ogicalName | |||||
| 249 | }, | |||||
| 250 | OwnerI d = new En tityRefere nce | |||||
| 251 | { | |||||
| 252 | Id = _salesM anagerId, | |||||
| 253 | Lo gicalName = SystemUs er.EntityL ogicalName | |||||
| 254 | }, | |||||
| 255 | Rollup QueryActua lIntegerId = goalRol lupQuery2. ToEntityRe ference() | |||||
| 256 | }; | |||||
| 257 | _secondChi ldGoalId = _serviceP roxy.Creat e(secondCh ildGoal); | |||||
| 258 | ||||||
| 259 | Console.Wr iteLine("S econd chil d goal"); | |||||
| 260 | Console.Wr iteLine("- ---------- ------"); | |||||
| 261 | Console.Wr iteLine("T arget: {0} ", | |||||
| 262 | second ChildGoal. TargetInte ger.Value) ; | |||||
| 263 | Console.Wr iteLine("S tretch Tar get: {0}", | |||||
| 264 | second ChildGoal. StretchTar getInteger .Value); | |||||
| 265 | Console.Wr iteLine("G oal owner: {0}", sec ondChildGo al.GoalOwn erId.Id); | |||||
| 266 | Console.Wr iteLine("G oal Fiscal Period: { 0}", | |||||
| 267 | second ChildGoal. FiscalPeri od.Value); | |||||
| 268 | Console.Wr iteLine("G oal Fiscal Year: {0} ", | |||||
| 269 | second ChildGoal. FiscalYear .Value); | |||||
| 270 | Console.Wr iteLine(); | |||||
| 271 | ||||||
| 272 | #endregion | |||||
| 273 | ||||||
| 274 | #region Ca lculate ro llup and d isplay res ult | |||||
| 275 | ||||||
| 276 | // Calcula te roll-up of goals. | |||||
| 277 | Recalculat eRequest r ecalculate Request = new Recalc ulateReque st() | |||||
| 278 | { | |||||
| 279 | Target = new Ent ityReferen ce(Goal.En tityLogica lName, _pa rentGoalId ) | |||||
| 280 | }; | |||||
| 281 | _servicePr oxy.Execut e(recalcul ateRequest ); | |||||
| 282 | ||||||
| 283 | Console.Wr iteLine("C alculated roll-up of goals."); | |||||
| 284 | ||||||
| 285 | // Retriev e and repo rt 3 diffe rent compu ted values for the g oals | |||||
| 286 | // - Perce ntage | |||||
| 287 | // - Compu tedTargetA sOfTodayPe rcentageAc hieved | |||||
| 288 | // - Compu tedTargetA sOfTodayIn teger | |||||
| 289 | QueryExpre ssion retr ieveValues = new Que ryExpressi on() | |||||
| 290 | { | |||||
| 291 | Entity Name = Goa l.EntityLo gicalName, | |||||
| 292 | Column Set = new ColumnSet( | |||||
| 293 | "t itle", | |||||
| 294 | "p ercentage" , | |||||
| 295 | "c omputedtar getasoftod aypercenta geachieved ", | |||||
| 296 | "c omputedtar getasoftod ayinteger" ) | |||||
| 297 | }; | |||||
| 298 | EntityColl ection ec = _service Proxy.Retr ieveMultip le(retriev eValues); | |||||
| 299 | ||||||
| 300 | // Compute and displ ay the res ults | |||||
| 301 | for (int i = 0; i < ec.Entitie s.Count; i ++) | |||||
| 302 | { | |||||
| 303 | Goal t emp = (Goa l)ec.Entit ies[i]; | |||||
| 304 | Consol e.WriteLin e("Roll-up details f or goal: { 0}", temp. Title); | |||||
| 305 | Consol e.WriteLin e("------- --------") ; | |||||
| 306 | Consol e.WriteLin e("Percent age: {0}", temp.Perc entage); | |||||
| 307 | Consol e.WriteLin e("Compute dTargetAsO fTodayPerc entageAchi eved: {0}" , | |||||
| 308 | te mp.Compute dTargetAsO fTodayPerc entageAchi eved); | |||||
| 309 | Consol e.WriteLin e("Compute dTargetAsO fTodayInte ger: {0}", | |||||
| 310 | te mp.Compute dTargetAsO fTodayInte ger.Value) ; | |||||
| 311 | Consol e.WriteLin e("<End of Listing>" ); | |||||
| 312 | } | |||||
| 313 | ||||||
| 314 | #endregion | |||||
| 315 | ||||||
| 316 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 317 | } | |||||
| 318 | //</ snippetRol lupAllGoal sForFiscal PeriodAndS tretchedTa rgetRevenu e1> | |||||
| 319 | } | |||||
| 320 | ||||||
| 321 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 322 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 323 | { | |||||
| 324 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 325 | thro w; | |||||
| 326 | } | |||||
| 327 | } | |||||
| 328 | ||||||
| 329 | // / <summary > | |||||
| 330 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 331 | // / </summar y> | |||||
| 332 | pu blic void CreateRequ iredRecord s() | |||||
| 333 | { | |||||
| 334 | ||||||
| 335 | #region Create or Retrieve t he necessa ry system users | |||||
| 336 | ||||||
| 337 | // Retri eve the ld apPath | |||||
| 338 | String l dapPath = String.Emp ty; | |||||
| 339 | // Retri eve the sa les team - 1 sales m anager and 2 sales r epresentat ives. | |||||
| 340 | _salesMa nagerId = | |||||
| 341 | Syst emUserProv ider.Retri eveSalesMa nager(_ser viceProxy, ref ldapP ath); | |||||
| 342 | _salesRe presentati veIds = | |||||
| 343 | Syst emUserProv ider.Retri eveSalespe rsons(_ser viceProxy, ref ldapP ath); | |||||
| 344 | ||||||
| 345 | #endregi on | |||||
| 346 | ||||||
| 347 | #region Create Pho neCall rec ord and su pporting a ccount | |||||
| 348 | ||||||
| 349 | Account account = new Accoun t | |||||
| 350 | { | |||||
| 351 | Name = "Margie 's Travel" , | |||||
| 352 | Addr ess1_Posta lCode = "9 9999" | |||||
| 353 | }; | |||||
| 354 | _account Id = (_ser viceProxy. Create(acc ount)); | |||||
| 355 | account. Id = _acco untId; | |||||
| 356 | ||||||
| 357 | // Creat e Guids fo r PhoneCal ls | |||||
| 358 | _phoneCa llId = Gui d.NewGuid( ); | |||||
| 359 | _phoneCa ll2Id = Gu id.NewGuid (); | |||||
| 360 | ||||||
| 361 | // Creat e Activity Partys for the phone calls' "F rom" field . | |||||
| 362 | Activity Party acti vityParty = new Acti vityParty( ) | |||||
| 363 | { | |||||
| 364 | Part yId = acco unt.ToEnti tyReferenc e(), | |||||
| 365 | Acti vityId = n ew EntityR eference | |||||
| 366 | { | |||||
| 367 | Id = _phon eCallId, | |||||
| 368 | LogicalNam e = PhoneC all.Entity LogicalNam e, | |||||
| 369 | }, | |||||
| 370 | Part icipationT ypeMask = new Option SetValue(9 ), | |||||
| 371 | }; | |||||
| 372 | ||||||
| 373 | Activity Party acti vityPartyC losed = ne w Activity Party() | |||||
| 374 | { | |||||
| 375 | Part yId = acco unt.ToEnti tyReferenc e(), | |||||
| 376 | Acti vityId = n ew EntityR eference | |||||
| 377 | { | |||||
| 378 | Id = _phon eCall2Id, | |||||
| 379 | LogicalNam e = PhoneC all.Entity LogicalNam e, | |||||
| 380 | }, | |||||
| 381 | Part icipationT ypeMask = new Option SetValue(9 ) | |||||
| 382 | }; | |||||
| 383 | ||||||
| 384 | // Creat e an open phone call . | |||||
| 385 | PhoneCal l phoneCal l = new Ph oneCall() | |||||
| 386 | { | |||||
| 387 | Id = _phoneCal lId, | |||||
| 388 | Subj ect = "Sam ple Phone Call", | |||||
| 389 | Dire ctionCode = false, | |||||
| 390 | To = new Activ ityParty[] { activit yParty }, | |||||
| 391 | Owne rId = new EntityRefe rence("sys temuser", _salesRepr esentative Ids[0]), | |||||
| 392 | Actu alEnd = Da teTime.Now | |||||
| 393 | }; | |||||
| 394 | _service Proxy.Crea te(phoneCa ll); | |||||
| 395 | ||||||
| 396 | // Close the first phone cal l. | |||||
| 397 | SetState Request cl osePhoneCa ll = new S etStateReq uest() | |||||
| 398 | { | |||||
| 399 | Enti tyMoniker = phoneCal l.ToEntity Reference( ), | |||||
| 400 | Stat e = new Op tionSetVal ue(1), | |||||
| 401 | Stat us = new O ptionSetVa lue(4) | |||||
| 402 | }; | |||||
| 403 | _service Proxy.Exec ute(closeP honeCall); | |||||
| 404 | ||||||
| 405 | // Creat e a second phone cal l. | |||||
| 406 | phoneCal l = new Ph oneCall() | |||||
| 407 | { | |||||
| 408 | Id = _phoneCal l2Id, | |||||
| 409 | Subj ect = "Sam ple Phone Call 2", | |||||
| 410 | Dire ctionCode = true, | |||||
| 411 | To = new Activ ityParty[] { activit yParty }, | |||||
| 412 | Owne rId = new EntityRefe rence("sys temuser", _salesRepr esentative Ids[1]), | |||||
| 413 | Actu alEnd = Da teTime.Now | |||||
| 414 | }; | |||||
| 415 | _service Proxy.Crea te(phoneCa ll); | |||||
| 416 | ||||||
| 417 | // Close the secon d phone ca ll. | |||||
| 418 | closePho neCall = n ew SetStat eRequest() | |||||
| 419 | { | |||||
| 420 | Enti tyMoniker = phoneCal l.ToEntity Reference( ), | |||||
| 421 | Stat e = new Op tionSetVal ue(1), | |||||
| 422 | Stat us = new O ptionSetVa lue(4) | |||||
| 423 | }; | |||||
| 424 | _service Proxy.Exec ute(closeP honeCall); | |||||
| 425 | ||||||
| 426 | #endregi on | |||||
| 427 | ||||||
| 428 | } | |||||
| 429 | ||||||
| 430 | // / <summary > | |||||
| 431 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 432 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 433 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 434 | // / </summar y> | |||||
| 435 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 436 | { | |||||
| 437 | // The t hree syste m users th at were cr eated by t his sample will cont inue to | |||||
| 438 | // exist on your s ystem beca use system users can not be del eted in Mi crosoft | |||||
| 439 | // Dynam ics CRM. They can o nly be ena bled or di sabled. | |||||
| 440 | ||||||
| 441 | bool toB eDeleted = true; | |||||
| 442 | ||||||
| 443 | if (prom pt) | |||||
| 444 | { | |||||
| 445 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 446 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 447 | Stri ng answer = Console. ReadLine() ; | |||||
| 448 | if ( answer.Sta rtsWith("y ") || | |||||
| 449 | answer.Sta rtsWith("Y ") || | |||||
| 450 | answer == String.Emp ty) | |||||
| 451 | { | |||||
| 452 | toBeDelete d = true; | |||||
| 453 | } | |||||
| 454 | else | |||||
| 455 | { | |||||
| 456 | toBeDelete d = false; | |||||
| 457 | } | |||||
| 458 | } | |||||
| 459 | ||||||
| 460 | if (toBe Deleted) | |||||
| 461 | { | |||||
| 462 | // D elete all records cr eated in t his sample . | |||||
| 463 | _ser viceProxy. Delete("go al", _firs tChildGoal Id); | |||||
| 464 | _ser viceProxy. Delete("go al", _seco ndChildGoa lId); | |||||
| 465 | _ser viceProxy. Delete("go al", _pare ntGoalId); | |||||
| 466 | _ser viceProxy. Delete("go alrollupqu ery", _rol lupQueryId s[0]); | |||||
| 467 | _ser viceProxy. Delete("go alrollupqu ery", _rol lupQueryId s[1]); | |||||
| 468 | _ser viceProxy. Delete("ac count", _a ccountId); | |||||
| 469 | _ser viceProxy. Delete("ph onecall", _phoneCall Id); | |||||
| 470 | _ser viceProxy. Delete("ph onecall", _phoneCall 2Id); | |||||
| 471 | _ser viceProxy. Delete("ro llupfield" , _actualI d); | |||||
| 472 | _ser viceProxy. Delete("me tric", _me tricId); | |||||
| 473 | ||||||
| 474 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 475 | } | |||||
| 476 | } | |||||
| 477 | ||||||
| 478 | #e ndregion H ow To Samp le Code | |||||
| 479 | ||||||
| 480 | #r egion Main method | |||||
| 481 | ||||||
| 482 | // / <summary > | |||||
| 483 | // / Standard Main() me thod used by most SD K samples. | |||||
| 484 | // / </summar y> | |||||
| 485 | // / <param n ame="args" ></param> | |||||
| 486 | st atic publi c void Mai n(string[] args) | |||||
| 487 | { | |||||
| 488 | try | |||||
| 489 | { | |||||
| 490 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 491 | // c redentials from the user. | |||||
| 492 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 493 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 494 | ||||||
| 495 | Roll upAllGoals ForFiscalP eriodAndSt retchedTar getRevenue app = | |||||
| 496 | new Rollup AllGoalsFo rFiscalPer iodAndStre tchedTarge tRevenue() ; | |||||
| 497 | app. Run(config , true); | |||||
| 498 | } | |||||
| 499 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 500 | { | |||||
| 501 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 502 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 503 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 504 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 505 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 506 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 507 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 508 | } | |||||
| 509 | catch (S ystem.Time outExcepti on ex) | |||||
| 510 | { | |||||
| 511 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 512 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 513 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 514 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 515 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 516 | } | |||||
| 517 | catch (S ystem.Exce ption ex) | |||||
| 518 | { | |||||
| 519 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 520 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 521 | ||||||
| 522 | // D isplay the details o f the inne r exceptio n. | |||||
| 523 | if ( ex.InnerEx ception != null) | |||||
| 524 | { | |||||
| 525 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 526 | ||||||
| 527 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 528 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 529 | if (fe != null) | |||||
| 530 | { | |||||
| 531 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 532 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 533 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 534 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 535 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 536 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 537 | } | |||||
| 538 | } | |||||
| 539 | } | |||||
| 540 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 541 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 542 | ||||||
| 543 | finally | |||||
| 544 | { | |||||
| 545 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 546 | Cons ole.ReadLi ne(); | |||||
| 547 | } | |||||
| 548 | } | |||||
| 549 | #e ndregion M ain method | |||||
| 550 | } | |||||
| 551 | } | |||||
| 552 | //</snippe tRollupAll GoalsForFi scalPeriod AndStretch edTargetRe venue> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.