Project Server 2013 Updating Task level Lookup based custom field Using CSOM
Below sample code is to update the task level Lookup table based custom fields for a given project:
try{
projectName = "ProjectTest";
pwapath = "https://Servername/pwa";
projContext = new ProjectContext(pwapath);
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
var proj = projContext.Projects.First(p => p.Name == projectName);
projContext.ExecuteQuery();
var cfInternalName = "Custom_aaf4156c7804e511943500155d569905"; //CustomField field uid without the "-" and small letters
var draftProj = proj.CheckOut();
projContext.Load(draftProj.Tasks);
projContext.ExecuteQuery();
var tasks = draftProj.Tasks;
foreach (DraftTask tsk in tasks)
{
string[] Newval = new string[] { "Entry_343982d27604e511943500155d569905" }; //Lookup table value UID without "-" and small letters
tsk[cfInternalName] = Newval;
}
draftProj.Publish(true);
QueueJob qJob = projContext.Projects.Update();
JobState jobState = projContext.WaitForQueue(qJob, 200);
Console.ReadKey();
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
}
Console.ReadKey();
Happy coding ......Cheers .. Ajith