none
Project VBA: How get value Enterprise Custom Fields RRS feed

  • Question

  • I'm trying to get data from custom enterprise assignment-level fields:
    Dim t As Task
    Dim a As Assignment
    Dim ThisMin As Single
    For Each t In ActiveProject.Tasks
        If Not t Is Nothing Then
            If t.Summary <> True Then
                For Each ass_ In t.Assignments
                    MsgBox (ass_.someName) <--error this
                Next ass_
            End If
        End If
    Next t
    but when referring to him, I get the error:
    Object doesn't support this property or method
    I read on the forums that this method should work. Corporate fields have unique names.

    Thursday, October 20, 2016 9:28 AM

Answers

  • Hi,

    the above will work, when

    • your ECF is set to roll down to assignment level
    • AND there is no blank (" ") in your field name

    For field values on task or resource level, you can always use

    • T.GetField(FieldNameToFieldConstant("My Field Name", pjTask)) to retrieve value or
    • T.SetField FieldID:=FieldNameToFieldConstant("My Field Name", pjTask), Value:=MyValue

    using pjTask for tasks and pjResource for resources. In this case, it does not make any difference if a blank is included in field name.

    Unfortunately, FieldNameToFieldConstant is not avaliable for assignments. As long as there is no blank in Name, you can just use it as you described. So I assume a blank in your field name.

    The following does work:

    Sub SetAndReadECF()
    Dim T As Task
    Dim A As Assignment
    
    For Each T In ActiveProject.Tasks
        If Not T Is Nothing Then
            For Each A In T.Assignments
                MsgBox A.MyFieldNameWithoutBlank
                A.MyFieldNameWithoutBlank = "Test1"
            Next A
            MsgBox T.GetField(FieldNameToFieldConstant("My Field Name", pjTask))
            MsgBox T.GetField(FieldNameToFieldConstant("MyFieldNameWithoutBlank", pjTask))
            T.SetField FieldID:=FieldNameToFieldConstant("My Field Name", pjTask), Value:="Test2"
            T.SetField FieldID:=FieldNameToFieldConstant("MyFieldNameWithoutBlank", pjTask), Value:="Test3"
        End If
    Next T
    End Sub

    Does that help?
    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    Thursday, October 20, 2016 12:11 PM
    Moderator

All replies

  • Hi,

    the above will work, when

    • your ECF is set to roll down to assignment level
    • AND there is no blank (" ") in your field name

    For field values on task or resource level, you can always use

    • T.GetField(FieldNameToFieldConstant("My Field Name", pjTask)) to retrieve value or
    • T.SetField FieldID:=FieldNameToFieldConstant("My Field Name", pjTask), Value:=MyValue

    using pjTask for tasks and pjResource for resources. In this case, it does not make any difference if a blank is included in field name.

    Unfortunately, FieldNameToFieldConstant is not avaliable for assignments. As long as there is no blank in Name, you can just use it as you described. So I assume a blank in your field name.

    The following does work:

    Sub SetAndReadECF()
    Dim T As Task
    Dim A As Assignment
    
    For Each T In ActiveProject.Tasks
        If Not T Is Nothing Then
            For Each A In T.Assignments
                MsgBox A.MyFieldNameWithoutBlank
                A.MyFieldNameWithoutBlank = "Test1"
            Next A
            MsgBox T.GetField(FieldNameToFieldConstant("My Field Name", pjTask))
            MsgBox T.GetField(FieldNameToFieldConstant("MyFieldNameWithoutBlank", pjTask))
            T.SetField FieldID:=FieldNameToFieldConstant("My Field Name", pjTask), Value:="Test2"
            T.SetField FieldID:=FieldNameToFieldConstant("MyFieldNameWithoutBlank", pjTask), Value:="Test3"
        End If
    Next T
    End Sub

    Does that help?
    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    Thursday, October 20, 2016 12:11 PM
    Moderator
  • Yes Yes Yes!!!! Thank you so much!!
    I was not paying attention to your reply. After installation  in the Calculation for Assignment rows section, click Roll down, unless manually specified, everything worked.
    Thursday, October 20, 2016 1:30 PM