2016-05-23 14 views
1

Hat es jemand geschafft, benutzerdefinierte Felder programmgesteuert für eine Task oder ein Projekt zu aktualisieren, das Lookup-Werte verwendet? Ich benutze CSOM, Code ist unten, C#. Nachschlagen Benutzerdefiniertes Feld aktualisiert, aber Feld auf leer gesetzt, überschreibt vorherigen Wert, der mit Web App eingegeben wurde. Updates für 'Text' Benutzerdefinierte Felder funktionieren einwandfrei.Kann CustomField für eine Aufgabe oder ein Projekt mit GUID der Lookup-Tabelle mit csom nicht aktualisieren

private void SendCode() 
{ 
    ProjectContext context; 
    using (context = new ProjectContext(ConfigurationManager.AppSettings["psUrl"])) 
    { 
     context.Load(context.Projects, 
      pj => pj.Include(
       p => p.Id, 
       p => p.Name)); 
     context.Load(context.CustomFields, 
      lts => lts.Include(
       lt => lt.Name, 
       lt => lt.InternalName)); 

     context.ExecuteQuery(); 
     // Output Status is a Custom Filed referring to a lookup table called Output Status with 6 status values 
     string customFieldName = "Output Status"; 
     // A routine to get the correct GUID from the lookup Table 
     object customFieldValue = new Guid("1aded2bc-67ad-49e4-9c52-a9dca4ea09a5"); 
     foreach (PublishedProject pp in context.Projects) 
     { 
      DraftProject proj2Edit = pp.CheckOut().IncludeCustomFields; 
      context.Load(proj2Edit.Tasks, 
       ts => ts.Include(
        t => t.Id, 
        t => t.Name, 
        t => t.CustomFields, 
        t => t.OutlineLevel, 
        t => t.IsSummary)); 
      context.ExecuteQuery(); 
      var cfInternalName = context.CustomFields.First(cf => cf.Name == customFieldName).InternalName; 
      DraftTask newTask = proj2Edit.Tasks.First(t => t.Name == "REI and PPR Monitoring"); 
      newTask[cfInternalName] = customFieldValue; // How should you be setting the GUID? 
      proj2Edit.Publish(true); 
      QueueJob qJob = context.Projects.Update(); 
      JobState jobState = context.WaitForQueue(qJob, QueueTimeout); 
     } 
    } 
} 

Antwort

0