Hi,
The Assignment Enterprise Custom Fields cannot be accessed directly since it
is not a part of the other field lists. In VBA, we can access it directly by
specifying the name of the custom field. This will be evaluated at run time
through late binding.
In C#, we can call the InvokeMember method of Type object to get the value
of custom field. The sample code is given below:
// This code will get the value of the custom field (testcustom) of first
Assignment
// of first Task.
object objAssignment;
// we can explicitly mention the type of Assignment object as:
// Microsoft.Office.Interop.MSProject.Assignment objAssignment;
// Assign the first assignment to the object
objAssignment =
Globals.ThisAddin.Application.ActiveProject.Tasks[1].Assignments[1];
// Use InvokeMember to call the 'testcustom' custom field
MessageBox.Show(objAssignment.GetType().InvokeMember("testcustom",
BindingFlags.GetProperty | BindingFlags.InvokeMethod, null, objAssignment,
null).ToString());
If you are using VB.NET there is another way to get the value of custom
field which is similar to the one we use in VBA. The code goes as below:
Dim objAssignment as Object
' Here the assignment object should be explicitly declared as object not as
an
' Assignment object. Otherwise it will not work.
' Now assign the assignment of the task to the object
objAssignment =
Globals.ThisAddin.Application.ActiveProject.Tasks[1].Assignment[1]
' Get the value of the custom field by directly giving the custom field name
Msgbox(objAssignment.testcustom)
This method will not work in C# because it is a strongly typed language.
Please let me know if this helps you.