none
SetField no longer works in Project 2010 RRS feed

  • Question

  • SetTask doesn't seem to work in 2010.  We are using a VSTO addin and it fails with "The argument value is not valid".  I've tried many different formats but nothing seems to work.  I reproduced the error with a simple macro.  The below works in Project 2003/2007, but fails in 2010

    Public Sub Foo()
      Dim oTask As Task
      Dim sValue As String
      
      Set oTask = ThisProject.Tasks(1)
      sValue = oTask.GetField(pjTaskStart)
    
      ' Application-defined or object-defined error
      oTask.SetField pjTaskStart, sValue
    
    End Sub
    
    

     

    • Moved by Michael WhartonMVP, Moderator Thursday, July 29, 2010 8:30 PM Question is about development (From:Project Standard and Professional General Questions and Answers)
    Thursday, July 29, 2010 8:28 PM

Answers

  • Hi,

    Maybe that works in 2003/207 but I would never code it like that, this is what works in all versions:

     Set oTask = ActiveProject.Tasks(1)
      sValue = oTask.GetField(fieldnametofieldconstant("Start"))

    Greetings,

    Friday, July 30, 2010 5:43 AM
    Moderator

All replies

  • Hi,

    Maybe that works in 2003/207 but I would never code it like that, this is what works in all versions:

     Set oTask = ActiveProject.Tasks(1)
      sValue = oTask.GetField(fieldnametofieldconstant("Start"))

    Greetings,

    Friday, July 30, 2010 5:43 AM
    Moderator
  • Thanks!

    FieldNameToFieldConstant works for the macro code, which was a simple way to reproduce the issue with our VSTO add-in.  I will give it a try and let you know

    Friday, July 30, 2010 10:26 PM
  • That works in VSTO.  Now I'm curious why using the constant PjTaskStart is different from using FieldNameToFieldConstant 
    Friday, July 30, 2010 10:51 PM
  • Looks like FieldNameToFieldConstant return value is dependent on the version of MS Project.

    Calling FieldNameToFieldConstant("Start") in 2003 returns 188743715, which is pjTaskStart

    Calling FieldNameToFieldConstant("Start") in 2010 returns 188744965, which is pjTaskStartText

    Friday, July 30, 2010 11:15 PM
  • Hi,

    With 2010 a new feature is introduced: manually scheduled tasks. To make them work, some fields like start, finish, duration are "duplicated" in a certain way. There exists a second field of type text to save data unless they match the correct field type. For example you can enter "TDB" in start if the task is manually scheduled. A user is able to see his manually entered text or date in "Start", which is a text field. If he used a date, this date is also put to "Scheduled Start", which is a date field. If he used some other text, he will find project start date or current date (depending on his settings in options) in "Scheduled Start".

    So FieldNameToFieldConstant("Start") gives you a text field where you can find any string if a task is manually scheduled. To get the date field for start, you will need to use FieldNameToFieldConstant("Scheduled Start") in 2010 - it will return 188745018, which is pjTaskScheduledStart.

    This is the same for Finish and Duration.

    I hope my description is not too confusing?
    Regards
    Barbara

    Saturday, July 31, 2010 6:21 AM
    Moderator
  • Also there are international considerations.  On a German system for example you would need to use:

    (FieldNameToFieldConstant("Anfang", pjTask))

     

    to return the same constant as 'Start' on an English version. But if International use was important then you should probably use the pjField Enumerations anyway, and not have language specific strings in your code.  For example:

     

    Const pjTaskStartText = 188744965 (&HB400505)
        Member of MSProject.PjField

    The SDK also gives details of the change Barbara perfectly describes above for other enumerations in 2010, as well as other object model changes of which you should be aware.

    http://msdn.microsoft.com/en-us/library/ms474284.aspx

    See table 10 - Enumerations.

     

     


    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Tuesday, August 24, 2010 7:10 PM
    Owner
  • Hi Brian,

    if you mention German translations: There are some "interesting" new translations. Is there a place to post some suggestions? (I want my "Ende" back instead of "Fertig stellen" for Finish for example.)

    Regards
    Barbara

    Tuesday, August 24, 2010 7:19 PM
    Moderator
  • I have asked the question internally - I will post again once I have an answer.  Glad I didn't use 'Finish' for my example above :).
    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Tuesday, August 24, 2010 11:04 PM
    Owner
  • Hi Brian,

    if you had used Finish, I have had a reason to laugh loudly ;-). Looking forward to your answer and the opportunity to share my 'list' (it's not a lot).

    Regards
    Barbara

    Wednesday, August 25, 2010 8:23 AM
    Moderator
  • When we update Project Profile page field values like 'Project code' using Set field FieldNameToFieldConstant it’s not working in Project server/EPM 2010 where as its working fine on project server /PPM 2007

     

     Please suggest us some solution how to make it work in EPM 2010 as well.


    Neelam Gupta
    Monday, November 7, 2011 9:24 AM