Category Archives: Custom Workflow

CRM 2011 Changing CRM Active/Invoice Contract to Draft

I have written article how to do this in CRM 4.0 at this place,Following source code for similar class in CRM 2011.

CRM2011ContractUtilities

This comes as dcoument (.doc) but download and rename as .zip and it will have all source files. this was done because wordpress only allows these types to be uploaded.

Once downloaded steps are similair to CRM 4.0 Article but still mentioned below again for reference..

Step 1: Download the application files (as mentioned above rename .doc to .zip and extract the files) and register this assembly using plug in registration tool.

Step 2: Once assembly is registered successfully, go to setting and create new workflow against contract, make sure contract is owned by admin user who have access to modify the database tables.

Step 3: Call this workflow “Change Status to Draft” and add step from Contract utilities -> Change Status to Draft. (Or whatever group name, friendly name you put in plug in registration tool)

Step 4: provide input parameters (i.e. database connection to string)

Step 5: Now publish the workflow.

Step 6: go to contract screen and run this workflow against relevant active/invoiced contract record and this workflow will make contract draft. Now user can change any field on this contract or delete the contract now

Note: This is unsupported customization, Please unit test this module on your development/test environment before applying it to Live Environment..

Hope this helps!!!

Cheers,
MayankP:)

Advertisements

CRM 2011: Removing Email from queue

Last year I blogged about this on CRM 4.0 but since last few months lots of users queried about similar solution for CRM 2011. This blog entry hopefully will provide solution for this.

Well solution logic is same as CRM 4.0, we will create custom workflow which will take email id and source queue id as input parameter and then custom will removed this email from relevant queue.

I have done following are steps to achieve this in CRM 2011.

Step 1:
Create new VS studio project and add necessary reference (i.e. Microsoft.Xrm.Sdk , Microsoft.Xrm.Sdk.Workflow etc.). for more information on how to create custom workflow activity for 2011 refer following article
http://technet.microsoft.com/en-us/library/gg328515.aspx

Step 2 :
Add new class called RemoveEmail.cs and I have provided full source code for this class at end of this article. (or it can be downloaded from http://snipt.org/xoGi)

Step 3 :
Register custom workflow assembly on 2011 dynamics server using Plug in Registration Tool.
for more information on how to register custom workflow activity for 2011 refer following article http://technet.microsoft.com/en-us/library/gg328515.aspx

Step 4:
following screen print of on demand workflow I have created for this in CRM 2011 for testing purpose.

That’s it, Done. if you need more information or got any more queries regarding this please drop comment below.
Hope this helps..

Cheers,
MayankP:)

Source Code


using System;
using System.Activities;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Client;

namespace CRM2011WorkflowUtilities
{
public class RemoveEmail : CodeActivity
{
protected override void Execute(CodeActivityContext executionContext)
{
try
{
//Create the context and tracing service
IExecutionContext context = executionContext.GetExtension();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracer = executionContext.GetExtension();

EntityReference incomingEmail = activityId.Get(executionContext);
string emailID = incomingEmail.Id.ToString();

EntityReference incomingQueue = queueId.Get(executionContext);
string queueID = incomingQueue.Id.ToString();

//Get the QueueItemID
Guid queueItemId = GetQueueItem(service,emailID,queueID);

//delete relevant queue item record and it will remmoved email from queue
if (queueItemId != Guid.Empty)
{
service.Delete("queueitem", queueItemId);
}
}
catch (Exception ex)
{
Helpers.Throw(String.Format("An error occurred in the {0} plug-in.",
this.GetType().ToString()),
ex);
}

return;
}

///

/// Retrieve Queue Item for this email and queue
///

///
///
///
///
private Guid GetQueueItem(IOrganizationService service,string emailGUID,string QueueGUID)
{
Guid queueItemId = Guid.Empty;

// Share the same access rights as the user, so we must retrieve the user's access rights to the record
QueryExpression qe = new QueryExpression();
qe.EntityName = "queueitem";
qe.ColumnSet = new ColumnSet();
qe.ColumnSet.AllColumns = true;

FilterExpression filter = new FilterExpression();

ConditionExpression hasEmailId = new ConditionExpression();
hasEmailId.AttributeName = "objectid";
hasEmailId.Operator = ConditionOperator.Equal;
hasEmailId.Values.Add(emailGUID) ;

ConditionExpression hasQueueId = new ConditionExpression();
hasQueueId.AttributeName = "queueid";
hasQueueId.Operator = ConditionOperator.Equal;
hasQueueId.Values.Add(QueueGUID);

filter.Conditions.Add(hasEmailId);
filter.Conditions.Add(hasQueueId);

qe.Criteria = filter;

EntityCollection ec = service.RetrieveMultiple(qe);

if (ec != null && ec.Entities.Count > 0)
{
queueItemId = ec.Entities[0].Id;
}

return queueItemId;

}

#region Input Parameters

[RequiredArgument]
[Input("Source Email Id")]
[ReferenceTarget("email")]
public InArgument activityId { get; set; }

[Input("queue Id")]
[ReferenceTarget("queue")]
public InArgument queueId { get; set; }

#endregion

#region Output Parameters

#endregion
}
}

Multiple owners on CRM 4.0 entities

CRM 4.0 entities record only is owned by one user only and this is really big limitation in CRM 4.0.

I was wondering for the possibility to have multiple owners per entity in Microsoft Dynamics CRM 4.0.
While searching the solution over net I have come across potential solution as below.

As per this blog article,

There are many instances where businesses want multiple “owners” of something within CRM. Having multiple users own something comes in many different forms when related to CRM. Examples include team selling using CRM Opportunity records, team support using Cases, and Tasks assigned to a group. Microsoft CRM is constructed such that one user is the “owner” of each record within CRM. Can we alter the system to modify this ownership?

Depending on the functionality you are looking to support, assigning multiple owners to a record can be accomplished many different ways in CRM. The question to start with is what functionality your business needs to support with multiple “owners” of something within in CRM.

Solution is based on the possibility to have multiple owners per entity identified as multi-owners using the sharing capability and deep customizations.

The multi-ownership currently will be automatically created and managed for leads, accounts and contacts entity.

Source Link

Cheers,
MayankP:)

CRM Plug-in / Custom Workflow debugging check list

UPDATE (30/07/2010) : I haved updated few steps based on comments from Andriy Butenko (CRM MVP)

If you got plug in or custom workflow application which is not working as expected on CRM server or giving unexpected error then following is the check list to set up for debugging Plug in/Custom workflow application.

1-Ensure that your plug-in is signed ( For Custom workflow this step is optional)

2-Rebuild the plug-in/Custom workflow

3-Restart CRM web site (i.e. run an iisreset command on server)

4. Also restart CRM Asynchronous Service on CRM server

5-copy the .pdb file and your .dll file to server\bin\assembly

6-Register the Plug-in Registration Tool V2 (http://code.msdn.com/crmplugin)

7. Refer to your dll in bin\assembly

8. Make it disk deployment (This step is also optional)

9-Register the step

10-Register the image if needed for relevant Plug-in

11- Open the relevant application in visual studio and click on Debug -> attach and then
select w3wp.exe if Synchronous plug-in or
select CRMAsyncService if asynchronous plug-in or Custom workflow.

12. You must be all set by then and just need to put breakpoint on relevant code line.

Note:- steps 9 & 10 are not needed for custom workflow application.

SOURCE

Hope this helps…

Cheers,
MayankP:)

Changing CRM Active/Invoice Contract to Draft

Sometime back I posted on how to change/delete read only records in Dynamics CRM but this does not work for contract.

Contract record once becomes active/invoice there is no supported way to change the contract back to draft. So I created custom workflow activity which allows users to change contract back to draft.
Once contract is in draft state, user can change any fields or delete the contract from the system.
I have shared this utility on CodePlex at Here

This application also contains some other contract utility. Following are the details steps regarding usage of this application

Step 1: Download the application files and register this assembly using plug in registration tool

Step 2 : Once assembly is registered successfully, go to setting and create new workflow against contract, make sure contract is owner by admin user who have access to modify the database tables.

Step 3: Call this workflow “Change Status to Draft” and add step from Contract utilities -> Change Status to Draft. (As per following screen print).

Step 4: provide input parameters (i.e. database connection to string)

Step 5: Now publish the workflow.

Step 6: go to contract screen and run this workflow against relevant active/invoiced contract record and this workflow will make contract draft. Now user can change any field on this contract or delete the contract now

Note: This is unsupported customization, Please unit test this module on your development/test environment before applying it to Live Environment..

Perform Action for 1:N and N:N Relationship in CRM 4.0 workflow editor

currently CRM 4.0 workflow editor allow you to update relevant record with N:1 relationship only, for example if you are in case screen then you can update related Account/Contact record only but if you want to update all tasks related to Case then you cannot able do it currently in Out of the box system.

Just came across this new project on codeplex which provides custom workflow which you can just register and this will extend (or add new action sub menu) in workflow editor screen to allow performing action for 1:N and N:N Relationship.

Following is the details from the CodePlex Site

Project Description
This plug-n allows to execute a workflow for each entity that has a 1:N or N:N relationship to a given entity.
For example: execute a workflow for each case related to an account (1:N), or for each competitor related to an opportunity (N:N), etc.

Summary
With CRM 4.0 out-of-the-box it is possible to perform actions on entities that have a N:1 relationship to a given entity, For example from an opportunity it is possible to update or run a workflow on the parent customer.

This plug-in allows to extend this to the other two possible relationships: 1:N and N:N. With the aid of this plugin it is possible to perform an action on each opportunity given the parent customer (1:N) or on each competitor given the opportunity (N:N) or on each opportunity given the competitor (other way of the same N:N).

Installation
Copy the .dll to the Microsoft Dynamics CRM\Server\bin\assembly folder
Run the Plug-in Registration tool and register the .dll
If the plug-in was registered successfully, a new action sub-menu (Utilities) will be available when selecting a workflow action.

Download Project documentation and files : http://crm40distributewf.codeplex.com/

Removing email from CRM queue

Currently if there is email in queue and if user manually creates case then case gets creates but email remains in the CRM queue.

Another scenario is that there is automated workflow which creates case for the email which comes in queue and workflow creates case fine but email remains in the queue.

For above two problems there is not out of the box method to remove or detach the email from the queue. However when I check CRM 4.0 SDK there is API DetachFromQueueEmailRequest Based on which I have created following generic custom workflow which takes queue id and email id as Input and removes the relevant email from the relevant queue.

Following is full code snippet for this..

Register this custom workflow using Plug in Registration Tool and you can use this utility in CRM workflow screen now…

Code can be downloaded from following link
View & Download Code File