<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://dotnetdeveloper.co.uk/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'Callouts'</title><link>http://dotnetdeveloper.co.uk/search/SearchResults.aspx?o=DateDescending&amp;tag=Callouts&amp;orTags=0</link><description>Search results matching tag 'Callouts'</description><dc:language>en-US</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>MS CRM - Automatically sharing an entity</title><link>http://dotnetdeveloper.co.uk/blogs/mscrm/archive/2008/09/16/ms-crm-automatically-sharing-an-entity.aspx</link><pubDate>Tue, 16 Sep 2008 10:40:00 GMT</pubDate><guid isPermaLink="false">86eca113-8d7a-4e3e-acb1-20f766f1d10b:58</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;This functionality is not&amp;nbsp;supported by Microsoft CRM, to share an entity automatically you have a few options&amp;nbsp;callouts or workflows.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve included&amp;nbsp;some working&amp;nbsp;code (inner workings mostly pasted from the sdk)&amp;nbsp;for a postcreate callout which automatically shares an account, which should&amp;nbsp;point you in the&amp;nbsp;right direction.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ideally you would wrap in a try / catch to deal with any exceptions.&lt;/p&gt;
&lt;p&gt;public override void PostCreate(CalloutUserContext userContext, CalloutEntityContext entityContext, string postImageEntityXml)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;//&amp;nbsp;Create the Crm Service&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CrmService service = new CrmService();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;service.Credentials = System.Net.CredentialCache.DefaultCredentials;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;service.CallerIdValue = new CallerId();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;service.CallerIdValue.CallerGuid = userContext.UserId;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Create the SecurityPrincipal object.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SecurityPrincipal principal = new SecurityPrincipal();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Set the properties of the SecurityPrincipal object.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;principal.Type = SecurityPrincipalType.Team;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// PrincipalId is the guid of the user or team you want to have access.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;principal.PrincipalId = new Guid(&amp;quot;XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX&amp;quot;);&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Create the PrincipalAccess object.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PrincipalAccess principalAccess = new PrincipalAccess();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Set the properties of the PrincipalAccess object.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;principalAccess.Principal = principal;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Give the principal access as required.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;principalAccess.AccessMask = AccessRights.ReadAccess;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Create the target object for the request.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;TargetOwnedAccount target = new TargetOwnedAccount();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// EntityId is the GUID of the account you want to share&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;target.EntityId = entityContext.InstanceId;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Create the request object.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GrantAccessRequest grant = new GrantAccessRequest();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Set the properties of the request object.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;grant.PrincipalAccess = principalAccess;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;grant.Target = target;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Execute the request.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;GrantAccessResponse granted = (GrantAccessResponse)service.Execute(grant);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;/p&gt;</description></item><item><title>MS Crm Callout, Calculation total incident / activity time</title><link>http://dotnetdeveloper.co.uk/blogs/mscrm/archive/2008/04/15/ms-crm-callout-calculation-total-incident-activity-time.aspx</link><pubDate>Tue, 15 Apr 2008 15:01:00 GMT</pubDate><guid isPermaLink="false">86eca113-8d7a-4e3e-acb1-20f766f1d10b:43</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;This callout calculates how much time has been spent on activities within an incident.&lt;br /&gt;&lt;br /&gt;First thing I did was customise the incident entity to include an incident total time field which I made read only to protect the data.&lt;br /&gt;Now all we need is a callout to total up the total time of the incidents.&lt;br /&gt;I based this callout on incident resolution and created the following code.&lt;/p&gt;
&lt;p&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Diagnostics;&lt;br /&gt;using System.Globalization;&lt;br /&gt;using System.Reflection;&lt;br /&gt;using System.Xml;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Security.Principal;&lt;br /&gt;using Microsoft.Crm.Callout;&lt;br /&gt;using Microsoft.Win32;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;namespace DotNetDeveloper.Callout &lt;br /&gt;{&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// Summary description for CaseResolutionCallout.&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;public class CaseResolutionCallout : CrmCalloutBase&lt;br /&gt;{&lt;br /&gt;#region constructors&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// empty constructor&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;public CaseResolutionCallout()&lt;br /&gt;{}&lt;br /&gt;#endregion&lt;br /&gt;#region Public Methods&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;/// PreCalloutReturnValue&lt;br /&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;/// &amp;lt;param name=&amp;quot;userContext&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;/// &amp;lt;param name=&amp;quot;entityContext&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;/// &amp;lt;param name=&amp;quot;newStateCode&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;/// &amp;lt;param name=&amp;quot;newStatusCode&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;/// &amp;lt;param name=&amp;quot;errorMessage&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;public override PreCalloutReturnValue PreSetState(CalloutUserContext userContext, CalloutEntityContext entityContext, ref int newStateCode, ref int newStatusCode, ref string errorMessage)&lt;br /&gt;{&lt;br /&gt;// only do this for Incident resolution&lt;br /&gt;if (newStateCode == 1)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;try&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;// setup impersonation&lt;br /&gt;&amp;nbsp;using (CrmService service =&amp;nbsp; new CrmService())&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;service.Credentials = System.Net.CredentialCache.DefaultCredentials;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;service.CallerIdValue = new CallerId();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;service.CallerIdValue.CallerGuid = userContext.UserId;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// get total time spent on case&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CalculateTotalTimeIncidentRequest req = new CalculateTotalTimeIncidentRequest();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;req.IncidentId = new System.Guid(entityContext.InstanceId.ToString());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CalculateTotalTimeIncidentResponse resp = (CalculateTotalTimeIncidentResponse)service.Execute(req);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// update the case&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;incident inc = new incident();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;inc.incidentid = new Key();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;inc.incidentid.Value = new Guid(entityContext.InstanceId.ToString());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;inc. totalincidenttime = resp.TotalTime.ToString();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;service.Update(inc);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;catch (Exception ex)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;// error handling code&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;return PreCalloutReturnValue.Continue;&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Obviously you need to add a reference to the base callout class and also to the MSCRM Service.&lt;br /&gt;Associated Callout.Config.xml code&lt;br /&gt;&amp;lt;callout entity=&amp;quot;incident&amp;quot; event=&amp;quot;PreSetState&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;subscription assembly=&amp;quot;DotNetDeveloper.Callout.dll&amp;quot; class=&amp;quot;DotNetDeveloper.Callout.CaseResolutionCallout&amp;quot;&amp;gt;&amp;lt;/subscription&amp;gt;&lt;br /&gt;&amp;lt;/callout&amp;gt;&lt;/p&gt;
&lt;p&gt;Ok that done, upon running this callout you will find that the callout should works as expected and populate the totalincidenttime. &lt;br /&gt;One activity I would test more than others would be the appointment activity, as the method provided by Microsoft calculates the incorrect totaltime for appointments ( I came across the problem and solution and posted about it in this earlier post &lt;a class="" title="here" href="http://dotnetdeveloper.co.uk/blogs/mscrm/archive/2008/04/15/actual-duration-time-wrong.aspx" target="_blank"&gt;here&lt;/a&gt; .&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>