Answered by:
CRM 4.0 Conversion to CRM 2011 !!!!

Question
-
How to do the same in CRM 2011 format????
ICrmService crmService = context.CreateCrmService(false);
systemuser callingUser = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), context.UserId, new ColumnSet(new string[] { "domainname"
}));
hussain
Sunday, January 20, 2013 12:01 PM
Answers
-
Hi Hussain,
Try below code.
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ColumnSet cols1 = new ColumnSet(new String[] { "domainname" });
Entity bcd = (Entity)service.Retrieve("systemuser", context.UserId, cols1);
}
Chandan - http://mscrm-chandan.blogspot.in/ I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful !!!
- Proposed as answer by Chandan kumar Choudhary Monday, January 21, 2013 11:01 AM
- Marked as answer by Hussain Saffar Saturday, February 2, 2013 9:20 PM
Monday, January 21, 2013 5:42 AM -
Hello,
Everything what Chandan wrote is correct except one line:
instead of
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
should be used
IOrganizationService service = serviceFactory.CreateOrganizationService(null);
- Marked as answer by Hussain Saffar Sunday, February 3, 2013 1:43 PM
Monday, January 28, 2013 9:54 AMModerator
All replies
-
Hi Hussain,
Try below code.
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ColumnSet cols1 = new ColumnSet(new String[] { "domainname" });
Entity bcd = (Entity)service.Retrieve("systemuser", context.UserId, cols1);
}
Chandan - http://mscrm-chandan.blogspot.in/ I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful !!!
- Proposed as answer by Chandan kumar Choudhary Monday, January 21, 2013 11:01 AM
- Marked as answer by Hussain Saffar Saturday, February 2, 2013 9:20 PM
Monday, January 21, 2013 5:42 AM -
Hello,
Everything what Chandan wrote is correct except one line:
instead of
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
should be used
IOrganizationService service = serviceFactory.CreateOrganizationService(null);
- Marked as answer by Hussain Saffar Sunday, February 3, 2013 1:43 PM
Monday, January 28, 2013 9:54 AMModerator -
Hello Andrii,
What's the reason behind having null instead ?? I search eveywhere but I found context.UserId is the right value!!!
hussain
Saturday, February 2, 2013 9:43 PM -
Null should be used because in case null is passed - Endpoint is created with top privileges (you are authenticated from the same of System account).
So my code implements the same code as you've asked for 4.0.
Sunday, February 3, 2013 8:23 AMModerator