I am using CSOM in order to import Enterprise Resources in Project Server 2013 from an external file. Resources, in my case, have some custom fields. The code is the following:
private static void InitializeContext()
{
Context = new ProjectContext(PwaPath);
Context.Credentials = Credentials;
}
static void Main(string[] args)
{
InitializeContext();
// Load resources and custom fields
Context.Load(Context.EnterpriseResources);
Context.Load(Context.CustomFields);
Context.Load(Context.LookupTables);
Context.ExecuteQuery();
var newResourceId = Guid.NewGuid();
var newResourceInfo = new EnterpriseResourceCreationInformation
{
Id = newResourceId,
IsBudget = false,
IsGeneric = false,
IsInactive = false,
Name = "AName",
ResourceType = EnterpriseResourceType.Work
};
Context.EnterpriseResources.Add(newResourceInfo);
Context.EnterpriseResources.Update();
Context.Load(Context.EnterpriseResources);
Context.ExecuteQuery();
EnterpriseResource newResource = Context.EnterpriseResources.GetByGuid(newResourceId);
LookupTable lTable = Context.LookupTables.First(lut => lut.Name == "SomeText");
Context.Load(lTable.Entries);
Context.ExecuteQuery();
LookupEntry entry = lTable.Entries.First(c => c.FullValue.EndsWith("SomeText"));
CustomField cField = Context.CustomFields.First(c => c.Name == "aValue");
newResource[cField.InternalName] = entry.FullValue;
Context.EnterpriseResources.Update();
}
The last 2 lines of code should update the value (read from a lookup table) of the field, but they don't. Anybody has any idea why?
Thanks in advance.
P.s: This question is also asked on SO. In case it should be deleted just let me know and I will.