Skip to content

Latest commit

 

History

History
81 lines (46 loc) · 2.83 KB

Project.Task.SetField.md

File metadata and controls

81 lines (46 loc) · 2.83 KB
title ms.service api_name ms.assetid ms.date ms.localizationpriority
Task.SetField method (Project)
project-server
Project.Task.SetField
f25de144-79f0-9c19-500a-94708a1b29a1
06/08/2017
medium

Task.SetField method (Project)

Sets the value of the specified task custom field.

Syntax

expression. SetField( _FieldID_, _Value_ )

expression A variable that represents a Task object.

Parameters

Name Required/Optional Data type Description
FieldID Required Long For a local custom field, can be one of the PjField constants for task custom fields. For an enterprise custom field, use the FieldNameToFieldConstant method to get the FieldID.
Value Required String The value of the field.

Remarks

You can access project custom fields through the ProjectSummaryTask property.

Example

The following example uses the SetField method and the GetField method together with the FieldNameToFieldConstant and FieldConstantToFieldName methods.

  1. To use the example, use Project Web App to create an enterprise project text custom field named TestEntProjText.

  2. Restart Project Professional with a Project Server profile, so that it includes the new custom field.

  3. Create a project with some value for the TestEntProjText field, by using the Project Information dialog box.

  4. The TestEnterpriseProjectCF macro uses the FieldNameToFieldConstant method to find the projectField number, for example, 190873618.

  5. The macro shows the number and text value in a message box, by using the GetField method.

  6. The macro gets the field name by using the FieldConstantToFieldName method, sets a new value by using the SetField method, and then shows the field name and new value in another message box.

Sub TestEnterpriseProjectCF() 
    Dim projectField As Long 
    Dim projectFieldName As String 
    Dim message As String 
 
    projectField = FieldNameToFieldConstant("TestEntProjText", pjProject) 
 
    ' Show the enterprise project field number and old value. 
    message = "Enterprise project field number: " & projectField & vbCrLf 
    MsgBox message & ActiveProject.ProjectSummaryTask.GetField(projectField) 
 
    ActiveProject.ProjectSummaryTask.SetField FieldID:=projectField, Value:="This is a new value." 
 
    ' For a demonstration, get the field name from the field number, and verify the new value. 
    projectFieldName = FieldConstantToFieldName(projectField) 
    message = "New value for field: " & projectFieldName & vbCrLf 
    MsgBox message & ActiveProject.ProjectSummaryTask.GetField(projectField) 
End Sub

[!includeSupport and feedback]