Friday 29 June 2012

set and get some fileds in dynamic crm 2011

Senario:

how to read the Optional set value in the Dynamic crm 2011:

OptionSetValue type =(OptionSetValue) entity1["new_billingtype"];

DateTime start = Convert.ToDateTime(entity1["new_startdate"]);
                DateTime end = Convert.ToDateTime(entity1["new_enddate"]);
                TimeSpan span = end.Subtract(start);
                if (type.Value ==100000000) //Monthly
                {
                   totalmonths = span.Days / 30;
                }

how to read money field:


Money totallineamount = (Money)contact1["totallineitemamount"];

doing calculations with int field:


int fixdiff = Convert.ToInt32(contact1["new_fixeddifference"]);
Money invoicetotallineamt = new Money() { Value =(totallineamount.Value / fixdiff) };

Set the money field:


incidentEntity["totallineitemamount"] = invoicetotallineamt;

reading lookup field:


EntityReference customerref = (EntityReference)contact1["customerid"];

          

 Set the Lookup field

    Entity incidentEntity = new Entity();
                incidentEntity.LogicalName = "invoice";              
                incidentEntity["customerid"] = customerref;

Retrieve all records:


ColumnSet cols = new ColumnSet(true);
                var contact1 = service.Retrieve("salesorder", workflowcontext.PrimaryEntityId, cols);






No comments:

Post a Comment