Tag Cloud

CRM 2011 (161) CRM 4.0 (144) C# (116) JScript (109) Plugin (92) Registry (90) Techpedia (77) PyS60 (68) WScript (43) Plugin Message (31) Exploit (27) ShellCode (26) FAQ (22) JavaScript (21) Killer Codes (21) Hax (18) VB 6.0 (17) Commands (16) VBScript (16) Quotes (15) Turbo C++ (13) WMI (13) Security (11) 1337 (10) Tutorials (10) Asp.Net (9) Safe Boot (9) Python (8) Interview Questions (6) video (6) Ajax (5) VC++ (5) WebService (5) Workflow (5) Bat (4) Dorks (4) Sql Server (4) Aptitude (3) Picklist (3) Tweak (3) WCF (3) regex (3) Config (2) LINQ (2) PHP (2) Shell (2) Silverlight (2) TSql (2) flowchart (2) serialize (2) ASHX (1) CRM 4.0 Videos (1) Debug (1) FetchXml (1) GAC (1) General (1) Generics (1) HttpWebRequest (1) InputParameters (1) Lookup (1) Offline Plug-ins (1) OutputParameters (1) Plug-in Constructor (1) Protocol (1) RIA (1) Sharepoint (1) Walkthrough (1) Web.config (1) design patterns (1) generic (1) iframe (1) secure config (1) unsecure config (1) url (1)

Pages

Sunday, May 12, 2013

CrmService.Execute Method

The Execute method executes a message that represents either a specialized method or specific business logic.

Syntax

public Response Execute(
  Request  Request
);



 

Parameters

Request

Specifies a specific Request instance.

Return Value

Returns an instance of a Response. You must cast the return value of the Execute method to the specific instance of the response that corresponds to the Request parameter.

Remarks

To perform this action, the caller must have the necessary privileges to the entity type specified in the request class. The caller must also have access rights on the entity instances specified in the request class.

Example

The following example demonstrates the use of the Execute method.


   1:  //# [CrmService.Execute Method]
   2:  // Set up the CRM Service.
   3:  CrmAuthenticationToken token = new CrmAuthenticationToken();
   4:  // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
   5:  token.AuthenticationType = 0; 
   6:  token.OrganizationName = "AdventureWorksCycle";
   7:   
   8:  CrmService service = new CrmService();
   9:  service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
  10:  service.CrmAuthenticationTokenValue = token;
  11:  service.Credentials = System.Net.CredentialCache.DefaultCredentials;
  12:   
  13:  // Create the request object.
  14:  AddItemCampaignRequest add = new AddItemCampaignRequest();
  15:   
  16:  // Set the properties of the request object.
  17:  add.CampaignId = campaignId;
  18:  add.EntityId = productId;
  19:  add.EntityName = EntityName.product;
  20:   
  21:  // Execute the request.
  22:  AddItemCampaignResponse added = (AddItemCampaignResponse) service.Execute(add);

CrmService.Create Method

Creates an instance of an entity.

Syntax

public Guid Create(
  BusinessEntity  entity
);






Parameters

entity

Specifies an instance of a class derived from BusinessEntity of the type of entity to create.

Return Value

Returns a Guid type that contains the ID of the newly created entity.

Remarks

Use this method to create an instance of any Microsoft Dynamics CRM entity that supports the Create message.

For better performance, use this method instead of using the Execute method with the Create message.

To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see Create Privileges.

The owner of the newly created instance should also have the Read privilege for the entity type.

Example

The following example demonstrates the use of the Create method.



   1:  //# [CrmService.Create Method]

   2:  // Set up the CRM Service.

   3:  CrmAuthenticationToken token = new CrmAuthenticationToken();

   4:  // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.

   5:  token.AuthenticationType = 0; 

   6:  token.OrganizationName = "AdventureWorksCycle";

   7:   

   8:  CrmService service = new CrmService();

   9:  service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";

  10:  service.CrmAuthenticationTokenValue = token;

  11:  service.Credentials = System.Net.CredentialCache.DefaultCredentials;

  12:   

  13:  // Create the contact object.

  14:  contact contact = new contact();

  15:   

  16:  // Create the properties for the contact object.

  17:  contact.firstname = "Jesper";

  18:  contact.lastname = "Aaberg";

  19:  contact.address1_line1 = "23 Market St.";

  20:  contact.address1_city = "Sammamish";

  21:  contact.address1_stateorprovince = "MT";

  22:  contact.address1_postalcode = "99999";

  23:  contact.donotbulkemail = new CrmBoolean();

  24:  contact.donotbulkemail.Value = true;

  25:   

  26:  // Create the contact in Microsoft Dynamics CRM.

  27:  Guid contactGuid = service.Create(contact);

Saturday, May 11, 2013

CrmService.Delete Method

Deletes an entity instance.

Syntax

public void Delete(
  string  entityName,
  Guid  id
);



Parameters

entityName

Specifies a String containing the name of the entity. For more information, see Using Entity Names.

id

Specifies a GUID containing the ID of the entity instance you want to delete.

Return Value

No return value.

Remarks

Use this method to delete any instance of a Microsoft Dynamics CRM entity that supports the Delete message.

For better performance, use this method instead of using the Execute method with the Delete message.

To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see Delete Privileges.

For a description of how actions on a parent instance affect child instances, see Cascading Rules.

Example

The following example demonstrates the use of the Delete method.

   1:  //# [CrmService.Delete Method]
   2:  // Set up the CRM Service.
   3:  CrmAuthenticationToken token = new CrmAuthenticationToken();
   4:  // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
   5:  token.AuthenticationType = 0; 
   6:  token.OrganizationName = "AdventureWorksCycle";
   7:   
   8:  CrmService service = new CrmService();
   9:  service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
  10:  service.CrmAuthenticationTokenValue = token;
  11:  service.Credentials = System.Net.CredentialCache.DefaultCredentials;
  12:   
  13:  // contactGuid is the GUID of the record being deleted.
  14:  Guid contactGuid = new Guid("4D507FFE-ED25-447B-80DE-00AE3EB18B84");
  15:   
  16:  // Delete the contact.
  17:  // The EntityName indicates the EntityType of the object being deleted.
  18:  service.Delete(EntityName.contact.ToString(), contactGuid);

Friday, May 10, 2013

CRM 2011 Solutions

Solutions - Data Modeling


Solutions - Introduction


Solutions - Managed & UnManaged


Solutions - Publishing

CrmService.Fetch Method

[Applies to: Microsoft Dynamics CRM 4.0]

Retrieves entity instances in XML format based on the specified query expressed in the FetchXML query language.

Syntax

 public string Fetch(
  string  fetchXml
 );



Parameters

fetchXml

Specifies a String that contains the fetch query string to be executed.

Return Value

Returns an XML String type that contains the results of the query.

Remarks

Use this method to execute a query expressed in the FetchXML query language.

To perform this action, the caller must have the Read privilege to the entity types being retrieved and access rights on the entity instances retrieved.

Example

The following example demonstrates the use of the Fetch method.

   1:  //# [CrmService.Fetch Method]
   2:  // Set up the CRM Service.
   3:  CrmAuthenticationToken token = new CrmAuthenticationToken();
   4:  // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory Authentication.
   5:  token.AuthenticationType = 0; 
   6:  token.OrganizationName = "AdventureWorksCycle";
   7:   
   8:  CrmService service = new CrmService();
   9:  service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
  10:  service.CrmAuthenticationTokenValue = token;
  11:  service.Credentials = System.Net.CredentialCache.DefaultCredentials;
  12:   
  13:  // Retrieve all attributes for all accounts.
  14:  // Be aware that using all-attributes may adversely affect
  15:  // performance and cause unwanted cascading in subsequent 
  16:  // updates. A best practice is to retrieve the least amount of 
  17:  // data required.
  18:  string fetch1 = @"   <fetch mapping=""logical"">
  19:                    <entity name=""account"">
  20:                       <all-attributes/>
  21:                    </entity>
  22:                 </fetch>";
  23:   
  24:  // Fetch the results.
  25:  String result1 = service.Fetch(fetch1);
  26:   
  27:  // Retrieve the name and account ID for all accounts where
  28:  // the account owner's last name is not Cannon.
  29:  string fetch2 = @"<fetch mapping=""logical"">
  30:                    <entity name=""account"">
  31:                       <attribute name=""accountid""/>
  32:                       <attribute name=""name""/>
  33:                       <link-entity name=""systemuser"" to=""owninguser"">
  34:                          <filter type=""and"">
  35:                             <condition attribute=""lastname"" operator=""ne"" value=""Cannon""/>
  36:                          </filter>
  37:                       </link-entity>
  38:                    </entity>
  39:                 </fetch>";
  40:   
  41:  // Fetch the results.
  42:  String result2 = service.Fetch(fetch2);

How to Retrieve a List of Messages and Entities that Support Plug-ins

The following code displays a list of messages and entities that support plug-ins. This sample code can be found in the following file in the SDK download:



   1:  //# [How to Retrieve a List of Messages and Entities that Support Plug-ins ]

   2:  using System;

   3:  using System.Collections;

   4:  using CrmSdk;

   5:  using MetadataServiceSdk;

   6:  using Microsoft.Crm.Sdk.Utility;

   7:   

   8:  namespace Microsoft.Crm.Sdk.HowTo

   9:  {

  10:     public class RetrieveSupportedMessages

  11:     {

  12:        public static bool Run(string crmServerUrl, string orgName)

  13:        {

  14:           bool success = true;

  15:           

  16:           // Store all Create, Retrieve, Update, and Delete sdk messages supported by the account entity for verification.

  17:           ArrayList crudMessagesForVerification = new ArrayList();

  18:   

  19:           try

  20:           {

  21:              // Set up the CRM Services.  

  22:              CrmService service = 

  23:                  Microsoft.Crm.Sdk.Utility.CrmServiceUtility.GetCrmService(

  24:                  crmServerUrl, orgName);

  25:              service.PreAuthenticate = true;

  26:   

  27:              MetadataService metadataService =

  28:                  Microsoft.Crm.Sdk.Utility.CrmServiceUtility.GetMetadataService(

  29:                  crmServerUrl, orgName);

  30:              metadataService.PreAuthenticate = true;

  31:   

  32:              // Retrieve a list of all entities.

  33:              RetrieveAllEntitiesRequest allEntitiesRequest = 

  34:                  new RetrieveAllEntitiesRequest();

  35:              allEntitiesRequest.RetrieveAsIfPublished = true;

  36:              allEntitiesRequest.MetadataItems = MetadataItems.EntitiesOnly;

  37:   

  38:              // Execute the request.

  39:              RetrieveAllEntitiesResponse allEntitiesResponse =

  40:              (RetrieveAllEntitiesResponse)metadataService.Execute(allEntitiesRequest);

  41:   

  42:              // Create a query to get all related sdk messages. 

  43:              // An example SQL query that will be built for every entity:

  44:              // SELECT sdkmessage.name

  45:              // FROM   sdkmessage

  46:              // INNER JOIN sdkmessagefilter ON sdkmessagefilter.skdmessageid = sdkmessage.skdmessageid

  47:              // WHERE  sdkmessagefilter.primaryobjecttypecode = entity.LogicalName;

  48:              QueryExpression supportedMessagesQuery = new QueryExpression();

  49:              

  50:              // Iterate through the retrieved entities.

  51:              foreach (EntityMetadata entity in allEntitiesResponse.CrmMetadata)

  52:              {

  53:                 // Retrieve the supported message name for this entity.

  54:                 ColumnSet sdkMessageColumns = new ColumnSet();

  55:                 sdkMessageColumns.Attributes = new string[] { "name" };

  56:                 

  57:                 // Build the WHERE clause condition.

  58:                 ConditionExpression schemaNameCondition = new ConditionExpression();

  59:                 schemaNameCondition.AttributeName = "primaryobjecttypecode";

  60:                 schemaNameCondition.Operator = ConditionOperator.Equal;

  61:                 schemaNameCondition.Values = new object[1];

  62:                 schemaNameCondition.Values[0] = entity.LogicalName;

  63:                 

  64:                 // Create the WHERE clause filter.

  65:                 FilterExpression whereExpression = new FilterExpression();

  66:                 whereExpression.Conditions = 

  67:                     new ConditionExpression[] { schemaNameCondition };

  68:                 

  69:                 // Create the inner join link.

  70:                 LinkEntity innerJoinAccount = new LinkEntity();

  71:                 innerJoinAccount.JoinOperator = JoinOperator.Inner;

  72:                 innerJoinAccount.LinkCriteria = whereExpression;

  73:                 innerJoinAccount.LinkFromAttributeName = "sdkmessageid";

  74:                 innerJoinAccount.LinkFromEntityName =

  75:                     EntityName.sdkmessage.ToString();

  76:                 innerJoinAccount.LinkToAttributeName = "sdkmessageid";

  77:                 innerJoinAccount.LinkToEntityName =

  78:                     EntityName.sdkmessagefilter.ToString();

  79:   

  80:                 // Set the query properties.

  81:                 supportedMessagesQuery.EntityName = EntityName.sdkmessage.ToString();

  82:                 supportedMessagesQuery.ColumnSet = sdkMessageColumns;

  83:                 supportedMessagesQuery.LinkEntities = 

  84:                     new LinkEntity[] { innerJoinAccount };

  85:   

  86:                 // Retrieve all sdkmessage names for this entity.

  87:                 BusinessEntityCollection coll =

  88:                     service.RetrieveMultiple(supportedMessagesQuery);

  89:                 

  90:                 // Output the supported messages for this entity

  91:                 Console.WriteLine("============================================================================");

  92:                 Console.WriteLine("Entity: " + entity.LogicalName);

  93:                 if (coll.BusinessEntities.Length > 0)

  94:                 {

  95:                    Console.WriteLine("Supported Messages:");

  96:                 }

  97:                 else

  98:                 {

  99:                    Console.WriteLine("No Messages Supported.");

 100:                 }

 101:                 string sdkMessageName = string.Empty;

 102:                 foreach(BusinessEntity anSdkMessage in coll.BusinessEntities)

 103:                 {

 104:                    sdkMessageName = ((sdkmessage)anSdkMessage).name;

 105:                    Console.WriteLine("\t\t" + sdkMessageName);

 106:                    

 107:                    // Verify that the account entity supports create, retrieve, update, delete.

 108:                    if (entity.LogicalName == EntityName.account.ToString())

 109:                    {

 110:                       // Store all Create, Retrieve, Update, and Delete messages.

 111:                       if (sdkMessageName == "Create" || sdkMessageName == "Retrieve" ||

 112:                          sdkMessageName == "Update" || sdkMessageName == "Delete")

 113:                       {

 114:                          crudMessagesForVerification.Add(sdkMessageName);

 115:                       }

 116:                    }

 117:                 }

 118:              }

 119:   

 120:              #region check success

 121:   

 122:              // Validate that the 4 Create, Retrieve, Update, and Delete messages were found.

 123:              if (crudMessagesForVerification.Count != 4)

 124:              {

 125:                 success = false;

 126:              }

 127:   

 128:              #endregion

 129:           }

 130:           catch (System.Web.Services.Protocols.SoapException)

 131:           {

 132:              // Perform error handling here.

 133:              throw;

 134:           }

 135:           catch (Exception)

 136:           {

 137:              throw;

 138:           }

 139:   

 140:           return success;

 141:        }

 142:     }

 143:  }

Thursday, May 09, 2013

Use the Methods in the Outlook SDK Assembly

This sample shows how to use the methods and properties in the assembly Microsoft.Crm.Outlook.Sdk. Before running this sample, you should start Microsoft Dynamics CRM for Outlook.



   1:  //# [Use the Methods in the Outlook SDK Assembly ]

   2:  using System;

   3:  using CrmSdk;

   4:  using Microsoft.Crm.Sdk.Utility;

   5:  using Microsoft.Crm.Outlook.Sdk;

   6:   

   7:  namespace Microsoft.Crm.Sdk.HowTo.Outlook

   8:  {

   9:     public class CrmOutlookMethodsSample

  10:     {

  11:        public CrmOutlookMethodsSample()

  12:        {

  13:   

  14:        }

  15:        

  16:        // NOTE:  Before running this sample, you should start the Microsoft Dynamics CRM for Outlook.

  17:        

  18:        public static bool Run(string crmServerUrl, string orgName)

  19:        {

  20:           bool success = true;

  21:   

  22:           try

  23:           {

  24:              // Set up the CRM Service.  

  25:              CrmOutlookService outlookService = new CrmOutlookService();

  26:   

  27:              // Determine if the Outlook client is running.

  28:              if (outlookService.IsCrmClientLoaded)

  29:              {

  30:                 if (outlookService.IsCrmDesktopClient)

  31:                 {

  32:                    // Microsoft Dynamics CRM for Outlook cannot go offline.

  33:                    Console.WriteLine("CRM Client Desktop URL: " + outlookService.ServerUri.AbsoluteUri);

  34:                    Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

  35:                 }

  36:                 else

  37:                 {

  38:                    // See if Microsoft Dynamics CRM for Outlook with Offline Access is offline.

  39:                    if (outlookService.IsCrmClientOffline)

  40:                    {

  41:                       Console.WriteLine("CRM Client Offline URL: " + outlookService.ServerUri.AbsoluteUri);

  42:                       Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

  43:                       

  44:                       // Take Microsoft Dynamics CRM for Outlook online.

  45:                       Console.WriteLine("Going Online...");

  46:                       outlookService.GoOnline();

  47:                       

  48:                       // Sync up with Microsoft Dynamics CRM database.

  49:                       Console.WriteLine("Synchronizing with CRM...");

  50:                       outlookService.Sync(OutlookSyncType.Outlook);

  51:   

  52:                       Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

  53:                    }

  54:                    else

  55:                    {

  56:                       Console.WriteLine("CRM Client Online URL: " + outlookService.ServerUri.AbsoluteUri);

  57:                       Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

  58:                       

  59:                       // Before going offline, sync up with the Microsoft Dynamics CRM database.

  60:                       Console.WriteLine("Synchronizing with CRM...");

  61:                       outlookService.Sync(OutlookSyncType.Outlook);

  62:                       

  63:                       // Take Microsoft Dynamics CRM for Outlook offline.

  64:                       Console.WriteLine("Going Offline...");

  65:                       outlookService.GoOffline();

  66:   

  67:                       Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

  68:                    }

  69:                 }

  70:              }

  71:           }

  72:           catch (System.Web.Services.Protocols.SoapException)

  73:           {

  74:              // Perform error handling here.

  75:              throw;

  76:           }

  77:           catch (Exception)

  78:           {

  79:              throw;

  80:           }

  81:           

  82:           return success;

  83:        }

  84:     }

  85:  }