[PS2007] - Setting Project Custom Field using VSTO

G

godrid

Hi,

I would like to find out whether it is possible to update Project enterprise
custom field using VSTO. If yes, how would I be able to reference to a
enterprise custom field from the active project?

Regards
Godrid
 
R

Rod Gill

In VBA you use:

Activeproject.Tasks(1).SetField application.FieldNameToFieldConstant("Field
Name",pjTask),strValue

and

msgbox
Activeproject.Tasks(1).GetField(application.FieldNameToFieldConstant("Field
Name",pjTask))

VB should be almost exactly the same and I'm not sure about C#!
--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
G

godrid

Hi Rod,

Thanks for your reply. I am able to get and set task custom field, however I
am still having problem to get and set project custom field. I have try using
Activeproject.ProjectSummaryTask.SetField without success, is it the correct
method for project custom field?

Thanks and Best Regards
Godrid
 
G

godrid

Hi Rod,

I have managed to set and get from project custom field as well.

Initially, I use pjProject as parameter to the FieldNameToFieldConstant
function call instead of using pjTask. All the while I thought i should use
pjProject for project custom field, anyway now I am able to achieve the
objectives. Thanks again.

Best Regards
Godrid
 
L

lumar

Godrid,

I am facing the same issue: I am trying to programmatically create a new
project, applying a template to it and set the values of some project custom
fields.
So far I wasn't able to valorize those fields.
The problem is not getting the id if the fields, because I already know
them, just to insert the values.
Can you explain me which way you succeded?
 
G

godrid

Hi Lumar,

To set a project custom field, try the following:

Microsoft.Office.Interop.MSProject.Project proj =
Globals.ThisAddIn.Application.ActiveProject;

try
{
PjField field =
Globals.ThisAddIn.Application.FieldNameToFieldConstant(proj_properties,
PjFieldType.pjTask);
proj.ProjectSummaryTask.SetField(field, string_value);
}
catch (ArgumentException e)
{
MessageBox.Show(e.Message);
}

Note: proj_properties is the string of the project custom field that you
wanted to set and string_value is the string data that you wanted to update
to the project custom field.

That's how I set the project custom field, hope that helps.

Regards
Godrid
 
R

Rick Carville

I'm looking to update an Enterprise custom field that is set to a list, with
VBA There are 2 options (Open or Closed)

--> I can read the field easily as such: (Thanks to code from Mr. Gill)
MsgBox
ActiveProject.Tasks(1).GetField(Application.FieldNameToFieldConstant("Project
Status", pjTask))

--> However this code fails to work (when setting the strValue to "Closed"):

ActiveProject.Tasks(1).SetField
Application.FieldNameToFieldConstant("Project Status", pjTask), strValue

The error is "Run-time error "1101":
The argument value is not valid.

Any help would be greatly appriciated.

Regards,

Rick Carville
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top