Tag Archives: Custom Workflow

CRM 2011 Workflow Entity View records are not sorted alphabetically

I just recently come across customer reported CRM issue related workflow view displaying on demand workflow list random manner and not displaying them in alphabetically manner.

This issue mainly hits you if you got lots of workflow related to particular entity and while trying to run specific on demand workflow you will see lots of workflow in view and needs to manually sort the list to find your workflow.

B6510

Well looking at issue it seemed really easy issue to fix, so just open relevant view and apply sort on name column and publish the changes BUT this view is called “On Demand Workflows” is not customizable and hence we have to do unsupported change to fix this issue. Following steps done to fix this issue using unsupported manner.

Step 1: first find existing view and view definition from the data base. So run following query for this.

select savedqueryid,name,fetchxml from savedquerybase where name like '%On Demand Workflows%' order by name

Please note down savedqueryid as we will be using this in next steps.

B65112

Step 2: So following is the Original FetchXML definition for this view. As can be seen there is default sort order is not defined in this definition.

<fetch version="1.0" mapping="logical"><entity name="workflow"><attribute name="workflowid" /><attribute name="name" /><attribute name="createdon" /><attribute name="modifiedon" /><attribute name="statecode" /><attribute name="owningbusinessunit" /><attribute name="ownerid" /><filter type="and"><condition attribute="type" operator="eq" value="1" /><condition attribute="ondemand" operator="eq" value="true" /><condition attribute="statecode" operator="eq" value="1" /><condition attribute="category" operator="eq" value="0" /></filter></entity></fetch>

We will be Modifying above fetch xml with following to include sort order related to this. We refer highlighted change in fetchxml below for this.

<fetch version="1.0" mapping="logical"><entity name="workflow"><attribute name="workflowid" /><attribute name="name" /><attribute name="createdon" /><attribute name="modifiedon" /><attribute name="statecode" /><attribute name="owningbusinessunit" /><attribute name="ownerid" /><order attribute="name" descending="false" /><filter type="and"><condition attribute="type" operator="eq" value="1" /><condition attribute="ondemand" operator="eq" value="true" /><condition attribute="statecode" operator="eq" value="1" /><condition attribute="category" operator="eq" value="0" /></filter></entity></fetch>

Step 3: now update this specific view definition using SQL query against CRM database, please replace the SAVEDQUERYID with value noted down in step 1.

update savedquerybase
Set fetchxml ='<fetch version="1.0" mapping="logical"><entity name="workflow"><attribute name="workflowid" /><attribute name="name" /><attribute name="createdon" /><attribute name="modifiedon" /><attribute name="statecode" /><attribute name="owningbusinessunit" /><attribute name="ownerid" /><order attribute="name" descending="false" /><filter type="and"><condition attribute="type" operator="eq" value="1" /><condition attribute="ondemand" operator="eq" value="true" /><condition attribute="statecode" operator="eq" value="1" /><condition attribute="category" operator="eq" value="0" /></filter></entity></fetch>'
where name = 'On Demand Workflows'
and savedqueryid = 'SAVEDQUERYID';

After applying above changes log in to CRM and verify this view is displayed record correctly now.

B65113

****Important Notes regarding above change****
above change is unsupported so make sure you apply this change to Dev, Test environment before applying this to Live environment. Also make sure you take back up of database before doing this
change.

Hope this helps…

Cheers,
MayankP:)

Advertisements

CRM Server Report Issue

If you have custom workflow or application which renders SSRS report in CRM and generates PDF or excel as output and it you are using the same user to connect reporting service and generate this report then if you bulk generate lots of records then CRM throws following error on report server.

The report server has detected a possible denial of service attack. The report server is dropping requests for service from the IP address XXX.XX.XXX.XX.

This is because reporting service by default allows only 20 requests for same user. This is setting in Reporting Service configuration and you can update to your required value to fix this issue. (see below screen print for the same which updates value to 250)

Above reporting service configuration file can be found in C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer folder.

For more information on all Reporting service configurations please refer following article
http://msdn.microsoft.com/en-us/library/ms157273.aspx

Hope this helps..

Cheers,
MayankP 🙂

CRM 2011 Custom workflow error

Problem

Recently we encounter following error coming from some of custom workflow in CRM 2011 organization.

Workflow paused due to error: Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Expected non-empty Guid.Detail: -2147220989 Expected non-empty Guid. 2012-02-23T10:15:53.6646892Z -2147220970 System.ArgumentException: Expected non-empty Guid. Parameter name: id 2012-02-23T10:15:53.6646892Z at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Retrieve(String entityName, Guid id, ColumnSet columnSet, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType) at Microsoft.Crm.Extensibility.InprocessServiceProxy.RetrieveCore(String entityName, Guid id, ColumnSet columnSet) at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Retrieve(String entityName, Guid id, ColumnSet columnSet) at Microsoft.Crm.Workflow.Services.RetrieveActivityService.c__DisplayClass1.b__0(IOrganizationService sdkService) at Microsoft.Crm.Workflow.Services.ActivityServiceBase.ExecuteInTransactedContext(ActivityDelegate activityDelegate) at Microsoft.Crm.Workflow.Services.RetrieveActivityService.ExecuteInternal(ActivityContext executionContext, RetrieveEntity retrieveEntity) at Microsoft.Crm.Workflow.Services.RetrieveActivityService.Execute(ActivityContext executionContext, RetrieveEntity retrieveEntity) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Solution

As per MS KB article this issue is fixed in CRM 2011 roll up 4, But for us even after applying roll up 6 this issue is not getting resolved.

so we have to update existing custom workflow to have a work around to fix this issue, following is more detail on this workaround.

So this error comes if you returning entity look up as return parameter from custom workflow and this error comes if your custom workflow returns null look up system throws above error.

To resolve this we put additional parameters called Dummy (Account GUID) as string and Success then pass test account record GUID as parameter.

[Input("Dummy")]
public InArgument Dummy { get; set; }

[Output("success")]
public OutArgument success { get; set; }

we also updated custom workflow code to return this dummy account if we are not able return correct account.


// find matching account
Guid accountId = FindAccount(crmService, perameterEmail, perameterName);

if (!accountId.Equals(Guid.Empty))
{
this.accountId.Set(executionContext, new EntityReference("account", accountId));
success.Set(executionContext, true);
}
else
{

//return dummy account

this.accountId.Set(executionContext, new EntityReference("account", new Guid(Dummy.Get(executionContext))));
success.Set(executionContext, false);
}

In workflow editor we just need to check if this returned success flag, if it is true then we got correct Id and if it is false then it is dummy account.

So this workaround resolves this issue not nice but effective.

Hope this helps..

Cheers,
MayankP:)

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:)

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
}
}

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..

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