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

Tuesday, April 30, 2013

Convert a Fax to a Task

This sample code shows how to convert a fax to a task. The code first creates an incoming Fax activity, and then converts it to a Follow-up Task with a due date a week after it was received.

 
using System;
using Microsoft.Crm.Sdk.Utility;

namespace Microsoft.Crm.Sdk.HowTo
{
// Microsoft Dynamics CRM namespaces.
using CrmSdk;

///
/// This sample shows how to convert a fax into a task.
///

public class ConvertFaxToTask
{
static void Main(string[] args)
{
// TODO: Change the server URL and organization to match your Microsoft Dynamics CRM server and Microsoft Dynamics CRM organization.
ConvertFaxToTask.Run("http://localhost:5555", "CRM_Organization");
}

public static bool Run(string crmServerUrl, string orgName)
{
#region Setup Data Required for this sample.

bool success = false;

#endregion

try
{
// Set up the CRM service.
CrmService service = CrmServiceUtility.GetCrmService(crmServerUrl, orgName);
service.PreAuthenticate = true;

// Get the current user.
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest);

// Create the fax object.
fax fax = new fax();

// Set the properties of the fax.
fax.subject = "Test Fax";
fax.description = "New Fax";

// Create the party sending and receiving the fax.
activityparty party = new activityparty();

// Set the properties of the activity party.
party.partyid = new Lookup();
party.partyid.type = EntityName.systemuser.ToString();
party.partyid.Value = user.UserId;

// The party sends and receives the fax.
fax.from = new activityparty[] { party };
fax.to = new activityparty[] { party };

// Create the fax.
Guid createdFaxId = service.Create(fax);

// Retrieve the created fax.
// Be aware that using AllColumns may adversely affect
// performance and cause unwanted cascading in subsequent
// updates. A best practice is to retrieve the least amount of
// data required.
fax newFax = (fax)service.Retrieve(EntityName.fax.ToString(), createdFaxId, new AllColumns());

// Create the task object.
task task = new task();

// Set the properties of the task.
task.subject = "Follow Up: " + newFax.subject;

// Set the due date of the task.
task.scheduledend = new CrmDateTime();

// Get the date that the fax was received.
CrmDateTime endDate = newFax.createdon;

// Set the due date of the task to one week later.
task.scheduledend.Value = endDate.UniversalTime.AddDays(7).ToString();

// Create the task.
Guid createdTaskId = service.Create(task);

#region check success

if (createdTaskId != Guid.Empty)
{
success = true;
}

#endregion

#region Remove Data Required for this Sample

service.Delete(EntityName.fax.ToString(), createdFaxId);
service.Delete(EntityName.task.ToString(), createdTaskId);

#endregion
}
catch (System.Web.Services.Protocols.SoapException)
{
// Add your error handling code here.
}

return success;
}
}
}



CrmService.Retrieve Method

Retrieves an entity instance using the specified ID.

Syntax

public BusinessEntity Retrieve(
  string  entityName,
  Guid  id,
  ColumnSetBase  columnSet
);



Parameters

entityName

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

id

Specifies a Guid containing the ID of the entity to retrieve.

columnSet

Specifies the set of columns to retrieve. Pass null to retrieve only the primary key. To retrieve all columns, pass a new instance of the AllColumns class. See ColumnSetBase.

Return Value

Returns the BusinessEntity requested. The BusinessEntity contains only the columns specified by the columnSet parameter. The entity is of the type specified by the entityName parameter.

Remarks

Use this method to retrieve an instance of a Microsoft Dynamics CRM entity.

For better performance, use this method instead of using the Execute method with the Retrieve 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 Retrieve Privileges.

Example

The following example demonstrates the use of the Retrieve method.



// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url = "http://:/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the column set object that indicates the properties to be retrieved.
ColumnSet cols = new ColumnSet();

// Set the properties of the column set.
cols.Attributes = new string [] {"fullname"};

// contactGuid is the GUID of the record being retrieved.
Guid contactGuid = new Guid("4D507FFE-ED25-447B-80DE-00AE3EB18B84");

// Retrieve the contact.
// The EntityName indicates the EntityType of the object being retrieved.
contact contact = (contact)service.Retrieve(EntityName.contact.ToString(), contactGuid, cols);

Monday, April 29, 2013

Send a Custom E-mail for a Campaign Activity

The following sample shows how to send an e-mail for a campaign activity.



   1:  //# Send a Custom E-mail for a Campaign Activity 

   2:  public void SendEmail(Guid campaignActivityID)

   3:  {

   4:     CrmService service = new CrmService();

   5:     service.Credentials = 

   6:        System.Net.CredentialCache.DefaultCredentials;

   7:   

   8:     service.CallerIdValue = new CallerId();

   9:     // Replace the GUID with the GUID of your Microsoft Dynamics CRM

  10:     // Administrator.

  11:     service.CallerIdValue.CallerGuid =

  12:        new Guid("FD80F8E8-C852-DA11-B1FB-0007E94D105B");

  13:   

  14:     SendEmailRequest req = new SendEmailRequest();

  15:     req.EmailId = campaignActivityID;

  16:     req.TrackingToken = "";

  17:     req.IssueSend = true;

  18:   

  19:     try 

  20:     {

  21:        SendEmailResponse res =

  22:           (SendEmailResponse)service.Execute(req);

  23:     }

  24:     catch (System.Web.Services.Protocols.SoapException er)

  25:     {

  26:        //Process any error messages here.

  27:     }

  28:  }

Sunday, April 28, 2013

Convert a Fax to a Task

This sample code shows how to convert a fax to a task. The code first creates an incoming Fax activity, and then converts it to a Follow-up Task with a due date a week after it was received.



   1:  //# Convert a Fax to a Task 

   2:  using System;

   3:  using Microsoft.Crm.Sdk.Utility;

   4:   

   5:  namespace Microsoft.Crm.Sdk.HowTo

   6:  {

   7:      // Microsoft Dynamics CRM namespaces.

   8:      using CrmSdk;

   9:   

  10:     /// <summary>

  11:     /// This sample shows how to convert a fax into a task.

  12:     /// </summary>

  13:     public class ConvertFaxToTask

  14:     {

  15:        static void Main(string[] args)

  16:        {

  17:           // TODO: Change the server URL and organization to match your Microsoft Dynamics CRM server and Microsoft Dynamics CRM organization.

  18:           ConvertFaxToTask.Run("http://localhost:5555", "CRM_Organization");

  19:        }

  20:   

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

  22:        {

  23:           #region Setup Data Required for this sample.

  24:   

  25:           bool success = false;

  26:   

  27:           #endregion

  28:   

  29:           try

  30:           {

  31:              // Set up the CRM service.

  32:              CrmService service = CrmServiceUtility.GetCrmService(crmServerUrl, orgName);

  33:              service.PreAuthenticate = true;

  34:              

  35:              // Get the current user.

  36:              WhoAmIRequest userRequest = new WhoAmIRequest();

  37:              WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest);

  38:   

  39:              // Create the fax object.

  40:              fax fax = new fax();

  41:   

  42:              // Set the properties of the fax.

  43:              fax.subject = "Test Fax";

  44:              fax.description = "New Fax";

  45:   

  46:              // Create the party sending and receiving the fax.

  47:              activityparty party = new activityparty();

  48:   

  49:              // Set the properties of the activity party.

  50:              party.partyid = new Lookup();

  51:              party.partyid.type = EntityName.systemuser.ToString();

  52:              party.partyid.Value = user.UserId;

  53:   

  54:              // The party sends and receives the fax.

  55:              fax.from = new activityparty[] { party };

  56:              fax.to = new activityparty[] { party };

  57:   

  58:              // Create the fax.

  59:              Guid createdFaxId = service.Create(fax);

  60:   

  61:              // Retrieve the created fax.

  62:              // Be aware that using AllColumns may adversely affect

  63:              // performance and cause unwanted cascading in subsequent 

  64:              // updates. A best practice is to retrieve the least amount of 

  65:              // data required.

  66:              fax newFax = (fax)service.Retrieve(EntityName.fax.ToString(), createdFaxId, new AllColumns());

  67:   

  68:              // Create the task object.

  69:              task task = new task();

  70:   

  71:              // Set the properties of the task.

  72:              task.subject = "Follow Up: " + newFax.subject;

  73:   

  74:              // Set the due date of the task.

  75:              task.scheduledend = new CrmDateTime();

  76:   

  77:              // Get the date that the fax was received.

  78:                  CrmDateTime endDate = newFax.createdon;

  79:                  

  80:              // Set the due date of the task to one week later.

  81:                  task.scheduledend.Value = endDate.UniversalTime.AddDays(7).ToString();

  82:   

  83:              // Create the task.

  84:              Guid createdTaskId = service.Create(task);

  85:   

  86:              #region check success

  87:   

  88:              if (createdTaskId != Guid.Empty)

  89:              {

  90:                 success = true;

  91:              }

  92:   

  93:              #endregion

  94:   

  95:              #region Remove Data Required for this Sample

  96:   

  97:              service.Delete(EntityName.fax.ToString(), createdFaxId);

  98:              service.Delete(EntityName.task.ToString(), createdTaskId);

  99:   

 100:              #endregion

 101:           }

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

 103:           {

 104:              // Add your error handling code here.

 105:           }

 106:   

 107:           return success;

 108:        }

 109:     }

 110:  }

Saturday, April 27, 2013

Promote an E-mail Message to Microsoft Dynamics CRM

This sample code shows how to create an e-mail activity instance from the specified e-mail message.



using System;
using CrmSdk;
using Microsoft.Crm.Sdk.Utility;

namespace Microsoft.Crm.Sdk.HowTo.Email
{
public class DeliverPromoteEmail
{
public DeliverPromoteEmail()
{

}

public static bool Run(string crmServerUrl, string orgName)
{
bool success = false;

try
{
// Set up the CRM Service.
CrmService service = Microsoft.Crm.Sdk.Utility.CrmServiceUtility.GetCrmService(crmServerUrl, orgName);
service.PreAuthenticate = true;

#region Setup Data Required for this Sample

// Create a user to send an e-mail message to (To: field).
contact emailContact = new contact();
emailContact.firstname = "Adam";
emailContact.lastname = "Carter";
emailContact.emailaddress1 = "adam.carter@example.com";

// Create the contact.
Guid emailContactId = service.Create(emailContact);

// Get a system user to send the e-mail (From: field)
WhoAmIRequest systemUserRequest = new WhoAmIRequest();
WhoAmIResponse systemUserResponse = service.Execute(systemUserRequest) as WhoAmIResponse;

ColumnSet selectClause = new ColumnSet();
selectClause.Attributes = new string[] { "internalemailaddress" };

// Execute the request.
systemuser emailSender = service.Retrieve(EntityName.systemuser.ToString(), systemUserResponse.UserId, selectClause) as systemuser;

#endregion

// Create the request.
DeliverPromoteEmailRequest deliverEmailRequest = new DeliverPromoteEmailRequest();

// Set all required fields
deliverEmailRequest.Subject = "SDK Sample Email";
deliverEmailRequest.To = emailContact.emailaddress1;
deliverEmailRequest.From = emailSender.internalemailaddress;
deliverEmailRequest.Bcc = String.Empty;
deliverEmailRequest.Cc = String.Empty;
deliverEmailRequest.Importance = "high";
deliverEmailRequest.Body = "This message will create an email activity.";
deliverEmailRequest.MessageId = Guid.NewGuid().ToString();
deliverEmailRequest.SubmittedBy = "";
deliverEmailRequest.ReceivedOn = new CrmDateTime();
deliverEmailRequest.ReceivedOn.Value = DateTime.Now.ToString();

// We will not attach a file to the e-mail, but the Attachments property is required.
deliverEmailRequest.Attachments = new BusinessEntityCollection();
deliverEmailRequest.Attachments.EntityName = EntityName.activitymimeattachment.ToString();
deliverEmailRequest.Attachments.BusinessEntities = new activitymimeattachment[0];

// Execute the request.
DeliverPromoteEmailResponse deliverEmailResponse = (DeliverPromoteEmailResponse)service.Execute(deliverEmailRequest);

#region check success

// Query for the delivered e-mail and verify the status code is "Sent".
ColumnSet deliveredMailColumns = new ColumnSet();
deliveredMailColumns.Attributes = new string[] { "statuscode" };

email deliveredEmail = service.Retrieve(EntityName.email.ToString(), deliverEmailResponse.EmailId, deliveredMailColumns) as email;

if (deliveredEmail.statuscode.Value == EmailStatus.Sent)
{
success = true;
}

#endregion

#region Remove Data Required for this Sample

// Delete the sent e-mail messages.
service.Delete(EntityName.email.ToString(), deliveredEmail.activityid.Value);

// Delete the contacts created for e-mail messages.
service.Delete(EntityName.contact.ToString(), emailContactId);

#endregion
}
catch (System.Web.Services.Protocols.SoapException)
{
// Perform error handling here.
throw;
}
catch (Exception)
{
throw;
}

return success;
}
}
}


Upload an Attachment

The following code example demonstrates how to upload an attachment to a note programmatically.

Example

The following code example shows how to upload attachment to an annotation entity instance.

The code first creates an account entity instance, and then adds an attached note to it with a doc file as an attachment.

   1:   
   2:  using System;
   3:  using System.Collections.Generic;
   4:  using System.Text;
   5:  using System.IO;
   6:  using Microsoft.Crm.Sdk.Utility;
   7:   
   8:  namespace Microsoft.Crm.Sdk.HowTo
   9:  {
  10:      // Use the following Microsoft Dynamics CRM namespaces in the sample.
  11:      using CrmSdk;
  12:   
  13:      class UploadAttachment
  14:      {
  15:          static void Main(string[] args)
  16:          {
  17:              // TODO: Change the server URL and organization to match your 
  18:              //  Microsoft Dynamics CRM Server and Microsoft Dynamics CRM Organization.
  19:              UploadAttachment.Run("http://localhost:5555", "CRM_Organization");
  20:          }
  21:   
  22:          public static bool Run(string crmServerUrl, string orgName)
  23:          {
  24:              #region Setup Data Required for this Sample
  25:   
  26:              bool success = false;
  27:              
  28:              #endregion
  29:   
  30:              try
  31:              {
  32:                  // Set up the CRM Service.
  33:                  CrmService service = CrmServiceUtility.GetCrmService(crmServerUrl, orgName);
  34:                  service.PreAuthenticate = true;
  35:   
  36:                  // Create an account object.
  37:                  account acct = new account();
  38:   
  39:                  // Set the account properties.
  40:                  acct.accountnumber = "CRM102";
  41:                  acct.name = "Fourth Coffee";
  42:                  acct.address1_name = "Primary";
  43:                  acct.address1_line1 = "1234 Elm Street";
  44:                  acct.address1_city = "Redmond";
  45:                  acct.address1_stateorprovince = "WA";
  46:                  acct.address1_postalcode = "54199";
  47:   
  48:                  // Creates an account in the Crm.
  49:                  Guid createdAccountId = service.Create(acct);
  50:   
  51:                  // Now create the annotation object. 
  52:                  annotation note = new annotation();
  53:                  note.notetext = "This is a sample note";
  54:                  note.subject = "Test Subject";
  55:                  note.objectid = new Lookup();
  56:                  note.objectid.type = EntityName.account.ToString();
  57:                  
  58:                  // Sets the note's parent to the newly created account.
  59:                  note.objectid.Value = createdAccountId;
  60:                  note.objecttypecode = new EntityNameReference();
  61:                  note.objecttypecode.Value = EntityName.account.ToString();
  62:   
  63:                  // Create the note.
  64:                  Guid createdNoteId = service.Create(note);
  65:   
  66:                  #region Setup Additional Data Required for this Sample
  67:                  
  68:                  // Now convert the attachment to be uploaded to Base64 string.
  69:                  // This will create a doc file in the current folder of executable.
  70:                  string currentPath = System.Environment.CurrentDirectory.ToString();
  71:                  TextWriter tw = new StreamWriter(currentPath + "\\Crm" + createdNoteId.ToString() + ".doc");
  72:                  // Write a line of text to the file.
  73:                  tw.WriteLine("This document is for testing an attachment upload feature of CRM 4.0.");
  74:                  tw.Close();
  75:                  
  76:                  #endregion
  77:   
  78:                  // Open a file and read the contents into a byte array.
  79:                  FileStream stream = File.OpenRead(currentPath + "\\Crm" + createdNoteId.ToString() + ".doc");
  80:                  byte[] byteData = new byte[stream.Length];
  81:                  stream.Read(byteData, 0, byteData.Length);
  82:                  stream.Close();
  83:   
  84:                  // Encode the data using base64.
  85:                  string encodedData = System.Convert.ToBase64String(byteData);
  86:   
  87:                  // Now update the note.
  88:                  annotation updateNote = new annotation();
  89:                  updateNote.annotationid = new Key();
  90:                  // Set the Note ID that is being attached to.
  91:                  updateNote.annotationid.Value = createdNoteId;
  92:                  updateNote.documentbody = encodedData;
  93:                  updateNote.filename = "Crm" + createdNoteId.ToString() + ".doc";
  94:                  updateNote.mimetype = @"application\ms-word";
  95:                  service.Update(updateNote);
  96:   
  97:                  #region check success
  98:   
  99:                  if (createdNoteId != Guid.Empty)
 100:                  {
 101:                      success = true;
 102:                  }
 103:   
 104:                  #endregion
 105:   
 106:                
 107:                  #region Remove Data Required for this Sample
 108:   
 109:                  if (createdNoteId != Guid.Empty)
 110:                      service.Delete(EntityName.annotation.ToString(), createdNoteId);
 111:                  
 112:                  if(createdAccountId != Guid.Empty)
 113:                      service.Delete(EntityName.account.ToString(), createdAccountId);
 114:   
 115:                  if (File.Exists(currentPath + "\\Crm" + createdNoteId.ToString() + ".doc"))
 116:                      File.Delete(currentPath+"\\Crm" + createdNoteId.ToString() + ".doc");
 117:   
 118:                  #endregion
 119:         
 120:              }
 121:              catch (System.Web.Services.Protocols.SoapException err)
 122:              {
 123:                  string strError = String.Format("An error occurred. The message is {0}.  The detail is {1}.", err.Message, err.Detail.OuterXml.ToString());
 124:              }
 125:              
 126:              
 127:              return success;
 128:          }
 129:      }
 130:  }

Friday, April 26, 2013

Execute workflow using button


//Execute workflow on button click
var obttcode = "10032";
var wrkflo_id = "{154599DD-B20B-4F72-8771-CA93C660C820}";
launchOnDemandWorkflowForm(' ',obttcode,wrkflo_id); //Crm Defined function
alert("executed");