The following sample shows how to use each of the types found in Microsoft Dynamics CRM.
Input Parameter: Number
Example
public static DependencyProperty myNumberProperty = DependencyProperty.Register("myNumber", typeof(CrmNumber), typeof(CreateCustomEntity));
[CrmInput("My Integer")]
public CrmNumber myNumber
{
get
{
return (CrmNumber)base.GetValue(myNumberProperty);
}
set
{
base.SetValue(myNumberProperty, value);
}
}
Input Parameter: String
Example
public static DependencyProperty myStringProperty = DependencyProperty.Register("myString", typeof(System.String), typeof(CreateCustomEntity));
[CrmInput("My String")]
public string myString
{
get
{
return (string)base.GetValue(myStringProperty);
}
set
{
base.SetValue(myStringProperty, value);
}
}
Input Parameter: Boolean
Example
public static DependencyProperty myBooleanProperty = DependencyProperty.Register("myBoolean", typeof(CrmBoolean), typeof(CreateCustomEntity));
[CrmInput("My Boolean")]
public CrmBoolean myBoolean
{
get
{
return (CrmBoolean)base.GetValue(myBooleanProperty);
}
set
{
base.SetValue(myBooleanProperty, value);
}
}
Input Parameter: Lookup
Example
public static DependencyProperty myLookupProperty = DependencyProperty.Register("myLookup", typeof(Lookup), typeof(CreateCustomEntity));
[CrmInput("My Lookup")]
[CrmReferenceTarget("account")]
public Lookup myLookup
{
get
{
return (Lookup)base.GetValue(myLookupProperty);
}
set
{
base.SetValue(myLookupProperty, value);
}
}
Input Parameter: Picklist
Example
public static DependencyProperty myPicklistProperty = DependencyProperty.Register("myPicklist", typeof(Picklist), typeof(CreateCustomEntity));
[CrmInput("My Picklist")]
[CrmAttributeTarget("account", "industrycode")]
public Picklist myPicklist
{
get
{
return (Picklist)base.GetValue(myPicklistProperty);
}
set
{
base.SetValue(myPicklistProperty, value);
}
}
Input Parameter: DateTime
Example
public static DependencyProperty myDateTimeProperty = DependencyProperty.Register("myDateTime", typeof(CrmDateTime), typeof(CreateCustomEntity));
[CrmInput("My DateTime")]
public CrmDateTime myDateTime
{
get
{
return (CrmDateTime)base.GetValue(myDateTimeProperty);
}
set
{
base.SetValue(myDateTimeProperty, value);
}
}
Input Parameter: Decimal
Example
public static DependencyProperty myDecimalProperty = DependencyProperty.Register("myDecimal", typeof(CrmDecimal), typeof(CreateCustomEntity));
[CrmInput("My Decimal")]
public CrmDecimal myDecimal
{
get
{
return (CrmDecimal)base.GetValue(myDecimalProperty);
}
set
{
base.SetValue(myDecimalProperty, value);
}
}
Input Parameter: Money
Example
public static DependencyProperty myMoneyProperty = DependencyProperty.Register("myMoney", typeof(CrmMoney), typeof(CreateCustomEntity));
[CrmInput("My Money")]
public CrmMoney myMoney
{
get
{
return (CrmMoney)base.GetValue(myMoneyProperty);
}
set
{
base.SetValue(myMoneyProperty, value);
}
}
Input Parameter: Float
Example
public static DependencyProperty myFloatProperty = DependencyProperty.Register("myFloat", typeof(CrmFloat), typeof(CreateCustomEntity));
[CrmInput("My Float")]
public CrmFloat myFloat
{
get
{
return (CrmFloat)base.GetValue(myFloatProperty);
}
set
{
base.SetValue(myFloatProperty, value);
}
}
Input Parameter: Status
Example
public static DependencyProperty myStatusProperty = DependencyProperty.Register("myStatus", typeof(Status), typeof(CreateCustomEntity));
[CrmInput("My Status")]
[CrmAttributeTarget("account", "statuscode")]
public Status myStatus
{
get
{
return (Status)base.GetValue(myStatusProperty);
}
set
{
base.SetValue(myStatusProperty, value);
}
}
Output Parameter: Lookup
Example
public static DependencyProperty myOutLookupProperty = DependencyProperty.Register("myOutLookup", typeof(Lookup), typeof(CreateCustomEntity));
[CrmOutput("My Output Lookup")]
[CrmReferenceTarget("new_customentity")]
public Lookup myOutLookup
{
get
{
return (Lookup)base.GetValue(myOutLookupProperty);
}
set
{
base.SetValue(myOutLookupProperty, value);
}
}
Execute Method: Using Types
Example
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = (ICrmService)context.CreateCrmService();
DynamicEntity de = new DynamicEntity("new_customentity");
if (myBoolean != null)
{
de["new_boolean"] = myBoolean;
}
if (myDateTime != null)
{
de["new_datetime"] = myDateTime;
}
if (myDecimal != null)
{
de["new_decimal"] = myDecimal.Value.ToString();
}
if (myFloat != null)
{
de["new_float"] = myFloat;
}
if (myLookup != null)
{
de["new_lookup"] = myLookup;
}
if (myMoney != null)
{
de["new_money"] = myMoney;
}
if (myNumber != null)
{
de["new_number"] = myNumber;
}
if (myPicklist != null)
{
de["new_picklist"] = myPicklist;
}
if (myStatus != null)
{
de["new_status"] = myStatus.Value.ToString();
}
if (myString != null)
{
de["new_stringtext"] = myString;
de["new_memo"] = myString;
}
de["new_activationid"] = new Lookup(EntityName.workflow.ToString(),context.ActivationId);
myOutLookup = new Lookup("new_customentity", crmService.Create(de));
return ActivityExecutionStatus.Closed;
}