locked
How to create a record using InitializeFromRequest RRS feed

  • Question

  • Hi, 

    I want to create an account record which is a copy of an existing account. So i am using InitializeFromRequest class. When i create the record the attributes are not copying at all. Below is the code.

     Account acc = new Account();
                    acc.Name = "Xyz";
                    acc.AccountNumber = "6789";
                    acc.Id = service.Create(acc);
                    InitializeFromRequest req = new InitializeFromRequest();

                    req.TargetEntityName = "account";
                  //  req.TargetFieldType = TargetFieldType.All;
                    req.EntityMoniker = new EntityReference("account", acc.Id);

                    // Execute the request
                    InitializeFromResponse resp =
                        (InitializeFromResponse)service.Execute(req);


                    Guid newEntityId = service.Create(resp.Entity);

    Any help on this is much appreciated.



    Kruthi Hegde

    Tuesday, November 25, 2014 6:36 AM

Answers

  • Hi Kruthi,

    InitializeFromRequest can be used when there is a 1:N relationship between the entities. It is equivalent of creating a child record from the parent form. Now in your case We have 1:N relationship between account i.e. ParanetCustomerId. 

    For example there is a 1:N relationship between account and Sub Account. if you create a Sub Account from the Account subgrid  it will prefill the parentcustomer field and all the fields defined in the relationship mappings. So please check the mapping. I can see below OOB mapping only.

    Hope this helps!

    Thanks!

    Kalim Khan

    • Proposed as answer by Kalim Khan Tuesday, November 25, 2014 8:14 AM
    • Marked as answer by Kruthi Hegde Thursday, November 27, 2014 5:46 AM
    Tuesday, November 25, 2014 8:14 AM