The following actions I took did not result in any errors, but they did not update the business unit for my user:
QueryExpression query = new QueryExpression();
query.EntityName = "systemuser";
query.ColumnSet = new AllColumns();
ConditionExpression ce = new ConditionExpression();
ce.AttributeName = "businessunitid";
ce.Operator = ConditionOperator.Equal;
ce.Values = new string[] { My BU Guid };
ConditionExpression ce2 = new ConditionExpression();
ce2.AttributeName = "lastname";
ce2.Operator = ConditionOperator.Equal;
ce2.Values = new string[] { Users Lastname };
FilterExpression filter = new FilterExpression();
filter.Conditions = new ConditionExpression[] { ce, ce2 };
query.Criteria = filter;
try
{
BusinessEntityCollection UserCollection = crmService.RetrieveMultiple(query);
foreach (BusinessEntity be in UserCollection.BusinessEntities)
{
//Update users BU. Roles will need to be added back in.
Guid newBu = new Guid(New BU Guid);
systemuser su = (systemuser)be;
su.businessunitid.Value = newBu;
TargetUpdateSystemUser sysuserUpdate = new TargetUpdateSystemUser() { SystemUser = su };
UpdateRequest userBUUpdate = new UpdateRequest() { Target = sysuserUpdate };
crmService.Execute(userBUUpdate);
}
catch
{
}
This currently throws no errors and returns one user. However, when the user's BU was checked in CRM, nothing had changed. I also used a straightforward CRM service. Update (SU) doesn't work either, though. What else must I accomplish?
Here's a link that may help you.
Develop 1 Limited Blog | How to change process and stage programmatically