SharePoint 2013 custom workflow (Sequential) visual studio not assigning task
-
07-02-2021 - |
Domanda
I am creating a simple sequential workflow using VS 2015 in SP2013 on premise. Trying to assign a task to the user in a 'Domain\username' format. The problem is that it is creating a task but not assigning it to the specified user.
createTask1_TaskProperties1.AssignedTo = "Domain"+"\"+"username";
so when an item is added workflow is in progress and when you click on it you can see the task but 'Assigned to' column is empty.
I have tested assigning it to many users (Production users, test users). its only working with one live account of my colleague. that account was site collection admin so I added other test accounts and live accounts as site collection admin. it dint work.
I created a SharePoint group and assigned by retreiving from that group but still no luck. I used our own AD framework to retrieve the users and assign a task, but still no luck. I checked the logs and I compared the account for which it is working with the other which is not working and there is not much in the logs too: I will post the logs here Please see the logs below for working user and non working user: Please check and help me out as I am banging my head over this for two days.
Soluzione
For completeness:
If claims
are enabled, you need to provide the full claim, not only the "simple" login. Encoding the claim can be done via ConvertIdentifierToClaim
. Whether claims are needed or not can be tested via UseClaimsAuthentication
:
var userAccount = "domain\\user"
SPUser user;
if (web.Site.WebApplication.UseClaimsAuthentication)
{
var claim = SPClaimProviderManager.Local.ConvertIdentifierToClaim(userAccount, SPIdentifierTypes.WindowsSamAccountName);
user = web.EnsureUser(claim.ToEncodedString());
} else {
user = web.EnsureUser(userAccount);
}
Now, the user is available in the web
(so you're sure it can be assigned tasks). Use user.LoginName
as assignee.