Answered by:
Post Create Plugin for statecode

Question
-
Hi,
I'm using MSCRM 4.0
my scenario is when ever opportunity is created, few columns from the opportunity should get created in new_custom entity.
i have written a plugin for post create.its working fine for few columns
but i have problem with statecode attribute(data type is State) and ownerid attribute(data type is owner)
i'm not sure what type of coding should i use for this two fields
Sample Coding which i implemented for Lookup & picklist
Lookup lkpdealcategoryid = (Lookup)GetProperty("mssp_dealcategoryid", entity);
DataSet ds = FetchAll(lkpdealcategoryid.Value.ToString());
if (ds.Tables["result"].Rows.Count > 0)
{
OppHistory.new_product = ds.Tables["result"].Rows[0].ItemArray[1].ToString();
}
else
{
OppHistory.new_product = string.Empty;
}
Picklist lkpsalesstagecrm = (Picklist)GetProperty("new_salesstagecrm", entity);
OppHistory.new_salesstage = lkpsalesstagecrm.name;Note:Lookup & Picklist are working fine
Need Suggestion for OwnerID & Statecode
Owner ownerId = (Owner)GetProperty("ownerid", entity);
Thanks,
Saraswathy
Friday, August 6, 2010 2:05 PM
Answers
-
try to read statecode like below
string StateCodeValue = (String)EntityName.Properties["statecode"];
and you can set owner id as below
new_custom.ownerid = new Owner(EntityName.systemuser.ToString(), context.UserId);
Mahain : http://mahenderpal.wordpress.com- Proposed as answer by HIMBAPModerator Friday, August 6, 2010 3:18 PM
- Marked as answer by Jim Glass Jr Friday, August 6, 2010 4:07 PM
Friday, August 6, 2010 3:14 PMModerator
All replies
-
try to read statecode like below
string StateCodeValue = (String)EntityName.Properties["statecode"];
and you can set owner id as below
new_custom.ownerid = new Owner(EntityName.systemuser.ToString(), context.UserId);
Mahain : http://mahenderpal.wordpress.com- Proposed as answer by HIMBAPModerator Friday, August 6, 2010 3:18 PM
- Marked as answer by Jim Glass Jr Friday, August 6, 2010 4:07 PM
Friday, August 6, 2010 3:14 PMModerator -
you can use below code to set the owner:
Owner owner = new Owner();
owner.type = EntityName.systemuser.ToString();
owner.Value = user.UserId;Hope this helps.
Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM ConsultantFriday, August 6, 2010 3:14 PM -
Hi,
new_custom.ownerid = new Owner(EntityName.systemuser.ToString(), context.UserId);
string StateCodeValue = (String)EntityName.Properties["statecode"]
i have tried both the concept its not working :-(
Saturday, August 7, 2010 9:11 AM -
Saturday, August 7, 2010 3:22 PMModerator