Thursday, June 13, 2013

crm2011 - writing optionset values to the database using IOrganizationService

Create an enum in C#, with the same values as are in CRM2011:

public enum ApprovalStatus
{
    ReviewRequired = 657070000,
    Approved = 657070001,
    Rejected = 657070002

}

This is my method for doing the add:
   public void AddBillHeader(string org, ApprovalStatus approvalStatus, DateTime billingDate)
        {
            IOrganizationService svc = GetXrmService(org);
            Entity bh = new Entity("fcbt_billheader");
            bh["fcbt_billingdate"] = billingDate;
            bh["fcbt_approvalstatus"] = new OptionSetValue((int)approvalStatus);
            svc.Create(bh);
         }

No comments:

Post a Comment