MSCRM 4 Convert Standard enitity to Custom entity using InitializeFromRequest

Posted by user363727 on Stack Overflow See other posts from Stack Overflow or by user363727
Published on 2010-06-10T17:07:24Z Indexed on 2010/06/11 8:42 UTC
Read the original article Hit count: 360

Filed under:
|
|

Hi there,

I'm trying to convert an order and orderdetail lines to a custom entity and its child lines using InitializeFromRequest using the code below:

public void Convert(Guid FromEntityId, string FromEntityName, string ToEntityName)
    {
        try
        {
            // Set up the CRM Service.
            CrmService _service = GetCrmService();

            InitializeFromRequest req = new InitializeFromRequest();
            req.EntityMoniker = new Moniker(); // this is the very thing that does the job.

            req.EntityMoniker.Id = FromEntityId;
            req.EntityMoniker.Name = FromEntityName;
            req.TargetEntityName = ToEntityName;  //contact for our example req.

            req.TargetFieldType = TargetFieldType.ValidForCreate;
            InitializeFromResponse rps = (InitializeFromResponse)_service.Execute(req);
            //now the lead is converted to a contact, and you can see it in contacts.
            Guid entityId = _service.Create(rps.Entity);
            lblMsg.Text = "Done ID:" + entityId.ToString();
        }            
        catch (System.Web.Services.Protocols.SoapException se)
        {
            lblMsg.Text = "soap:" + se.Detail.InnerText;
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }

    }

Now i am able to get a custom entity created but all the attributes are empty despite me setting the mapping fields in the realtionship.

Any ideas on what i am missing or doing wrong?

Thanks in advance Andrew

© Stack Overflow or respective owner

Related posts about c#

Related posts about mscrm