No entity error - Dynamic Entity custom workflow not working?

No entity error - Dynamic Entity custom workflow not working?

Post by Sm9uYXRoYW » Fri, 10 Oct 2008 21:10:00


using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Reflection;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow;



namespace DynamicEntityWorkflow
{

[CrmWorkflowActivity("Dynamic Entity Workflow", "Custom workflows")]
public partial class DynamicEntityActivity
{

private void InitializeComponent()
{
this.Name = "Activity1";
}



protected override ActivityExecutionStatus
Execute(ActivityExecutionContext executionContext)
{

IContextService contextService =
(IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = context.CreateCrmService();

// Create Properties

LookupProperty accountid = new LookupProperty();
accountid.Name = "acme_accountid";
accountid.Value = new Lookup();
accountid.Value.Value = new
Guid("260FB27F-25E6-DC11-BEDA-0013210AC0BE");
accountid.Value.type = EntityName.account.ToString();

StringProperty name = new StringProperty();
name.Name = "acme_RocketName";
name.Value = "Titian";

// Create the DynamicEntity object.

DynamicEntity AcmeEntity = new DynamicEntity("Opportunity");

// Set the name of the entity type.
AcmeEntity.Name = "acme_rocket";

AcmeEntity.Properties.Add(name);
AcmeEntity.Properties.Add(accountid);

// Create the target.
TargetCreateDynamic targetCreate = new TargetCreateDynamic();
targetCreate.Entity = AcmeEntity;

// Create the request object.
CreateRequest create = new CreateRequest();

// Set the properties of the request object.
create.Target = targetCreate;

// Execute the request.
CreateResponse created =
(CreateResponse)crmService.Execute(create);

return ActivityExecutionStatus.Closed;


}
}
}

I get the waiting status and the error is "No Entity", what am i doing wrong?

Thank you in advance

Jonathan
 
 
 

No entity error - Dynamic Entity custom workflow not working?

Post by ?Utf-8?Q?M » Fri, 10 Oct 2008 22:38:12

DynamicEntity AcmeEntity = new DynamicEntity("Opportunity");

Entity names are case sensitive. A lowercase "opportunity" should work.

--
Michael Hhne, Microsoft Dynamics CRM MVP

CRM Blog: http://www.yqcomputer.com/

"Jonathan Nachman" < XXXX@XXXXX.COM > wrote in

 
 
 

No entity error - Dynamic Entity custom workflow not working?

Post by Rm96emllQm » Fri, 10 Oct 2008 22:55:01

onathan, Michael,

Actually you should use EntityName.opportunity.ToString, and use this same
technique wherever possible, as this will eliminate spelling errors.

Fozzie.

Fozzie says hard coded strings are evil. Eliminate them when you get the
chance.

"Michael Hhne" wrote:

 
 
 

No entity error - Dynamic Entity custom workflow not working?

Post by Sm9uYXRoYW » Fri, 10 Oct 2008 23:28:01

Michael, Fozzie

Entityname.opportunity.tostring didnt compile and "opportunity" has produced
a general error now, any idea whats wrong with the cold now?

thank you once again


using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Reflection;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow;



namespace DynamicEntityWorkflow
{

[CrmWorkflowActivity("Dynamic Entity Workflow", "Custom workflows")]
public partial class DynamicEntityActivity
{

private void InitializeComponent()
{
this.Name = "Activity1";
}



protected override ActivityExecutionStatus
Execute(ActivityExecutionContext executionContext)
{

IContextService contextService =
(IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = context.CreateCrmService();

// Create Properties

LookupProperty accountid = new LookupProperty();
accountid.Name = "acme_accountid";
accountid.Value = new Lookup();
accountid.Value.Value = new
Guid("260FB27F-25E6-DC11-BEDA-0013210AC0BE");
accountid.Value.type = EntityName.account.ToString();

StringProperty name = new StringProperty();
name.Name = "acme_RocketName";
name.Value = "Titian";

// Create the DynamicEntity object.

DynamicEntity AcmeEntity = new DynamicEntity("opportunity");

// Set the name of the entity type.
AcmeEntity.Name = "acme_rocket";

AcmeEntity.Properties.Add(name);
AcmeEntity.Properties.Add(accountid);

// Create the target.
TargetCreateDynamic targetCreate = new TargetCreateDynamic();
targetCreate.Entity = AcmeEntity;

// Create the request object.
CreateRequest create = new CreateRequest();

// Set the properties of the request object.
create.Target = targetCreate;

// Execute the request.
CreateResponse created =
(CreateResponse)crmService.Execute(create);

return ActivityExecutionStatus.Closed;


}
}
}
 
 
 

No entity error - Dynamic Entity custom workflow not working?

Post by Rm96emllQm » Sat, 11 Oct 2008 00:01:15

onathan,

Several suggestions spring to mind:

1) Create the entity in one of two ways. Either...

DynamicEntity AcmeEntity = new DynamicEntity("acme_rocket");

or...

DynamicEntity AcmeEntity = new DynamicEntity();
AcmeEntity.Name = "acme_rocket";

These two options are both the same.

2) Create the entity in Crm using the standard Create method. So instead of
doing all this...

// Create the target.
TargetCreateDynamic targetCreate = new TargetCreateDynamic();
targetCreate.Entity = AcmeEntity;

// Create the request object.
CreateRequest create = new CreateRequest();

// Set the properties of the request object.
create.Target = targetCreate;

// Execute the request.
CreateResponse created = (CreateResponse)crmService.Execute(create);

do this...

crmService.Create(AcmeEntity);

3) Try to start using the Microsoft.Crm.Sdk namespaces and classes in the
way they were intended, as they are there to help you. Your code below...

// Create Properties
LookupProperty accountid = new LookupProperty();
accountid.Name = "acme_accountid";
accountid.Value = new Lookup();
accountid.Value.Value = new Guid("260FB27F-25E6-DC11-BEDA-0013210AC0BE");
accountid.Value.type = EntityName.account.ToString();

StringProperty name = new StringProperty();
name.Name = "acme_RocketName";
name.Value = "Titian";

// Create the DynamicEntity object.
DynamicEntity AcmeEntity = new DynamicEntity("opportunity");

// Set the name of the entity type.
AcmeEntity.Name = "acme_rocket";
AcmeEntity.Properties.Add(name);
AcmeEntity.Properties.Add(accountid);

can be written much quicker as this (for example)...

// Create Entity
DynamicEntity acmeEntity = new DynamicEntity("acme_rocket");

// Add properties
acmeEntity.Properties("acme_accountid") = New
Lookup(EntityName.account.ToString(), new
Guid("260FB27F-25E6-DC11-BEDA-0013210AC0BE"));
acmeEntity.Properties("acme_rocketname") = "Titan";

A final point. All entity names and field names are case sensitive, so the
acme_accountid field and acme_RocketName fields must appear EXACTLY as they
are defioned within the Crm schema name.

Hope this helps...

Fozzie.

PS. 'EntityName.opportunity.ToString();' compiles fine for me! :)

"Jonathan Nachman" wrote: