locked
Post Asynchronous Plugin to create child records of newly created parent record RRS feed

  • Question

  • Hi

    Details:

    I have two entities : Parent and Child , I have created a relationship between them.

    Now what i want to do is when record is created for Parent entity, I want to insert few records in Child entity (number of records would be based on custom logic).

    Right now I have created Post Asysnchronous Plugin for Parent Entity using Parent pipeline.

    Code is not throwing any error but it is not working also.

    I do not know wheather what i am doing is correct.

     

     

     

    Monday, July 19, 2010 6:46 AM

Answers

  • Parent pipeline...

    Child pipeline is used in specific action... For example, when you change the state of a record, you use SetState message in parent pipeline but there is also an update of the statuscode. This statuscode is updated in the child pipeline.

    Child pipeline is used when basic actions (Create, Update, Delete) are done by the system after a specific action

     


    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Monday, July 19, 2010 8:09 AM
    Moderator
  • Hi,

    Try to use below code, Please remember to change NAMEofYourParentEntity in below line

    _APD_serviceplan_servicedetailsid.Value = new Lookup("NAMEofYourParentEntity", parentid);

    ICrmService service = context.CreateCrmService(true);
    Guid parentid = ((Guid)context.OutputParameters.Properties["id"]); //retrieves the parent id
    
    DynamicEntity spDetails = new DynamicEntity("apd_child");
    
    StringProperty _APD_name = new StringProperty();
    _APD_name.Name = "APD_name";
    _APD_name.Value = "Name103";
    spDetails.Properties.Add(_APD_name);
    
    StringProperty _APD_fields1 = new StringProperty();
    _APD_fields1.Name = "APD_fields1";
    _APD_fields1.Value = "Sep";
    spDetails.Properties.Add(_APD_fields1);
    
    LookupProperty _APD_serviceplan_servicedetailsid = new LookupProperty();
    _APD_serviceplan_servicedetailsid.Name = "APD_serviceplan_servicedetailsid";
    _APD_serviceplan_servicedetailsid.Value = new Lookup("NAMEofYourParentEntity", parentid);
    spDetails.Properties.Add(_APD_serviceplan_servicedetailsid);
    TargetCreateDynamic targetCreate = new TargetCreateDynamic();
    targetCreate.Entity = spDetails;
    // Create the request object.
    CreateRequest create = new CreateRequest();
    // Set the properties of the request object.
    create.Target = targetCreate;
    CreateResponse created = (CreateResponse)service.Execute(create);
    
    

    Mahain
    Tuesday, July 20, 2010 6:06 AM
    Moderator
  • As Tanguy said Implement try to catch SoapException

    refer

    http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapexception.aspx

    Aslo make sure name of entity and attributes are correct


    Mahain
    Tuesday, July 20, 2010 7:38 AM
    Moderator
  • Also review the checklist to debug plugin, if you are having issue to debug it

    refer

    http://mayankp.wordpress.com/2010/05/04/crm-plug-in-custom-workflow-debugging-check-list/


    Mahain
    Tuesday, July 20, 2010 6:56 AM
    Moderator
  • You should have a SoapException, just look into Detail.OuterXml property, that should give you the "real" error message
    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Tuesday, July 20, 2010 7:25 AM
    Moderator

All replies

  • Hi.

     

    You should check that Microsoft Asynchronous service works properly.


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Monday, July 19, 2010 7:07 AM
    Moderator
  • Yes it is working properly.

    because I tried to insert records in some different entity(independent) in same plugin and it works

    Monday, July 19, 2010 7:10 AM
  • should i use a parent pipeline or child pipeline?
    Monday, July 19, 2010 7:13 AM
  • Parent pipeline...

    Child pipeline is used in specific action... For example, when you change the state of a record, you use SetState message in parent pipeline but there is also an update of the statuscode. This statuscode is updated in the child pipeline.

    Child pipeline is used when basic actions (Create, Update, Delete) are done by the system after a specific action

     


    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Monday, July 19, 2010 8:09 AM
    Moderator
  • Addidtion information:

    Relationship Type: One to Many , both are custom entities.

    Monday, July 19, 2010 9:45 AM
  • Any help appreciated!!!!!!!!!
    Monday, July 19, 2010 6:30 PM
  • can any one provide me sample code.
    Tuesday, July 20, 2010 4:32 AM
  • Hi,

    What code you are using ???, Paste that code here, so that we can help you


    Mahain
    Tuesday, July 20, 2010 4:58 AM
    Moderator
  •             try
                {

                    ICrmService service = context.CreateCrmService(true);
                    Guid parentid = ((Guid)context.OutputParameters.Properties["id"]); //retrieves the parent id

                    DynamicEntity spDetails = new DynamicEntity("apd_child");
                    spDetails["APD_name"] = "Name103";
                    spDetails["APD_fields1"] = "Sep";
                    //spDetails.Properties.Add(new KeyProperty("apd_apd_serviceplan_apd_servicedetails", new Key(customerContact)));
                    //spDetails.Properties.Add(new KeyProperty("apd_servicedetailsid", new Key(Guid.NewGuid())));
                    //spDetails["APD_serviceplan_servicedetailsid"] = new Lookup();
                    spDetails["APD_foreignKeyid"] = parentid; //this column is created by system when 1:N relationship is build between parent and child
                    spDetails["APD_fields2"] = 12;
                    spDetails["APD_fields3"] =103;
                    service.Create(spDetails);

                 }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(ex.Message.ToString());
                }

    Tuesday, July 20, 2010 5:25 AM
  • Hi,

    Try to use below code, Please remember to change NAMEofYourParentEntity in below line

    _APD_serviceplan_servicedetailsid.Value = new Lookup("NAMEofYourParentEntity", parentid);

    ICrmService service = context.CreateCrmService(true);
    Guid parentid = ((Guid)context.OutputParameters.Properties["id"]); //retrieves the parent id
    
    DynamicEntity spDetails = new DynamicEntity("apd_child");
    
    StringProperty _APD_name = new StringProperty();
    _APD_name.Name = "APD_name";
    _APD_name.Value = "Name103";
    spDetails.Properties.Add(_APD_name);
    
    StringProperty _APD_fields1 = new StringProperty();
    _APD_fields1.Name = "APD_fields1";
    _APD_fields1.Value = "Sep";
    spDetails.Properties.Add(_APD_fields1);
    
    LookupProperty _APD_serviceplan_servicedetailsid = new LookupProperty();
    _APD_serviceplan_servicedetailsid.Name = "APD_serviceplan_servicedetailsid";
    _APD_serviceplan_servicedetailsid.Value = new Lookup("NAMEofYourParentEntity", parentid);
    spDetails.Properties.Add(_APD_serviceplan_servicedetailsid);
    TargetCreateDynamic targetCreate = new TargetCreateDynamic();
    targetCreate.Entity = spDetails;
    // Create the request object.
    CreateRequest create = new CreateRequest();
    // Set the properties of the request object.
    create.Target = targetCreate;
    CreateResponse created = (CreateResponse)service.Execute(create);
    
    

    Mahain
    Tuesday, July 20, 2010 6:06 AM
    Moderator
  • It is still not working.

    When i am adding child record through workflow, child record is created successfully.

    When I register plugin synchronously, it throws error: server was unable to process the request.

    When I register plugin Asynchronously, no error is thrown but child record is also not created but parent record is succeefully saved as it is a asyc!

    Tuesday, July 20, 2010 6:26 AM
  • Ok,

    I will suggest you to go for debug

    refer below KB article for how to debug you plugin

    http://msdn.microsoft.com/en-us/library/cc151088.aspx


    Mahain
    Tuesday, July 20, 2010 6:30 AM
    Moderator
  • I am not able to debug it may be because plugin is registered as asynchronous.

    Is there any way to debug asynchronous plugin?

    Tuesday, July 20, 2010 6:48 AM
  • sorry , let me attach to process: CrmAsyncService.exe

    Tuesday, July 20, 2010 6:51 AM
  • Also review the checklist to debug plugin, if you are having issue to debug it

    refer

    http://mayankp.wordpress.com/2010/05/04/crm-plug-in-custom-workflow-debugging-check-list/


    Mahain
    Tuesday, July 20, 2010 6:56 AM
    Moderator
  •  

    During debug, it is internally throwing the same error as : unable to process the request.

    Tuesday, July 20, 2010 7:19 AM
  • You should have a SoapException, just look into Detail.OuterXml property, that should give you the "real" error message
    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Tuesday, July 20, 2010 7:25 AM
    Moderator
  • As Tanguy said Implement try to catch SoapException

    refer

    http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapexception.aspx

    Aslo make sure name of entity and attributes are correct


    Mahain
    Tuesday, July 20, 2010 7:38 AM
    Moderator
  • Thanks a lot Mahender

    After debug , I got the other small bugs which i resolved and its working now.

    Tuesday, July 20, 2010 8:27 AM