locked
Create Dynamic Entity in Workflow Step RRS feed

  • Question

  • Hi,all

    I want to create custom entity via custom workflow.I set all of input that I need,and register this plugin but it dosen't work

    please guide me

    my code is:

    namespace

    ddc_generate_gauranty

    {

    [

    CrmWorkflowActivity("GenerateGauranty", "Customs")]

     

    public partial class GenerateGauranty: SequenceActivity

    {

     

    //type:Nvarchar

     

    public static DependencyProperty PrefixProperty = DependencyProperty.Register("Prefix", typeof(string), typeof(GenerateGauranty));

    [

    CrmInput("Prefix")]

     

    public string Prefix

    {

     

    get

    {

     

    return (string)base.GetValue(PrefixProperty);

    }

     

    set

    {

     

    base.SetValue(PrefixProperty, value);

    }

    }

     

    //type:Look Up

     

    public static DependencyProperty InvoicesProperty = DependencyProperty.Register("Invoices", typeof(Lookup), typeof(GenerateGauranty));

    [

    CrmReferenceTarget("invoice")]

    [

    CrmInput("Invoices")]

     

    public Lookup Invoices

    {

     

    get

    {

     

    return (Lookup)base.GetValue(InvoicesProperty);

    }

     

    set

    {

     

    base.SetValue(InvoicesProperty, value);

    }

    }

    //type:Date

     

    public static DependencyProperty ReplaceDateProperty = DependencyProperty.Register("ReplaceDate", typeof(CrmDateTime), typeof(GenerateGauranty));

    [

    CrmInput("ReplaceDate")]

     

    public CrmDateTime ReplaceDate

    {

     

    get

    {

     

    return (CrmDateTime)base.GetValue(ReplaceDateProperty);

    }

     

    set

    {

     

    base.SetValue(ReplaceDateProperty, value);

    }

    }

    //type:int

     

    public static DependencyProperty StartProperty = DependencyProperty.Register("Start", typeof(CrmNumber), typeof(GenerateGauranty));

    [

    CrmInput("Start")]

     

    public CrmNumber Start

    {

     

    get

    {

     

    return (CrmNumber)base.GetValue(StartProperty);

    }

     

    set

    {

     

    base.SetValue(StartProperty, value);

    }

    }

     

    //type:int

     

    public static DependencyProperty QuantityProperty = DependencyProperty.Register("Quantity", typeof(CrmNumber), typeof(GenerateGauranty));

    [

    CrmInput("Quantity")]

     

    public CrmNumber Quantity

    {

     

    get

    {

     

    return (CrmNumber)base.GetValue(QuantityProperty);

    }

     

    set

    {

     

    base.SetValue(QuantityProperty, value);

    }

    }

     

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

    {

     

    try

    {

     

    IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));

     

    IWorkflowContext workflowContext = contextService.Context;

     

    ICrmService crmService = workflowContext.CreateCrmService(true);

     

     

     

     

    if (Prefix != null && Start != null &&  ReplaceDate != null  && Quantity != null)

    {

     

    int S = Start.Value;

     

    for (int i = 0; i < Quantity.Value; i++)

    {

    Microsoft.Crm.Sdk.

    DynamicEntity Delivery = new Microsoft.Crm.Sdk.DynamicEntity();

    Delivery.Name =

    "ddc_delivery";

    Delivery.Properties =

    new PropertyCollection();

    Microsoft.Crm.Sdk.

    StringProperty SerialNumber = new StringProperty();

    SerialNumber.Name =

    "ddc_serialnumber";

    SerialNumber.Value =

    string.Concat(Prefix, S.ToString());

    Delivery.Properties.Add(SerialNumber);

    Microsoft.Crm.Sdk.

    LookupProperty Invoice = new LookupProperty();

    Product.Name =

    "ddc_invoiceid";

    Product.Value =

    new Lookup("invoice", Invoices.Value);

    Delivery.Properties.Add(Invoice);

    Microsoft.Crm.Sdk.

    CrmDateTimeProperty ReplaceDates = new CrmDateTimeProperty();

    RepairDates.Name =

    "ddc_replacedate";

    RepairDates.Value = ReplaceDate;

    Delivery.Properties.Add(ReplaceDates);

    crmService.Create(Delivery);

    S += 1;

    }

     

    return ActivityExecutionStatus.Closed;

    }

    Monday, August 30, 2010 7:24 AM

Answers

  •  

    Hi

    Also, if you are unable to register your workflow use tracing

    Enable tracing and check for more detail and post the details error here
    http://blogs.msdn.com/b/emeadcrmsupport/archive/2010/03/04/crmdiagtool4-for-microsoft-crm-4-0-available-now-on-the-emea-dynamics-crm-support-blog.aspx
     

    STEPS TO DEBUG

    ------------------------

    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.


    Hope this helps. Amar
    Monday, August 30, 2010 8:24 AM

All replies

  • Are you getting any error ???
    Mahain : http://mahenderpal.wordpress.com
    Monday, August 30, 2010 7:29 AM
    Moderator
  • no,but the custom entity dosen't create!!!!!!!!!!!!!!!

     

     

    Monday, August 30, 2010 8:08 AM
  • Monday, August 30, 2010 8:10 AM
    Moderator
  •  

    Hi

    Also, if you are unable to register your workflow use tracing

    Enable tracing and check for more detail and post the details error here
    http://blogs.msdn.com/b/emeadcrmsupport/archive/2010/03/04/crmdiagtool4-for-microsoft-crm-4-0-available-now-on-the-emea-dynamics-crm-support-blog.aspx
     

    STEPS TO DEBUG

    ------------------------

    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.


    Hope this helps. Amar
    Monday, August 30, 2010 8:24 AM
  • You're using the crmService.Create() method, to which you are supposed to pass a BusinessEntity, not DynamicEntity.

    Try the following:

    TargetCreateDynamic target = new TargetCreateDynamic();
    target.Entity = Delivery;
    
    CreateRequest reqCreate = new CreateRequest();
    reqCreate.Target = target;
    
    CreateResponse respCreate = (CreateResponse)crmService.Execute(reqCreate);
    
    

    --pogo (pat)
    Tuesday, August 31, 2010 3:06 AM