Table of contents
TOC
Collapse the table of content
Expand the table of content

Application.AddSiteColumn Method (Project)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Adds a column that becomes available for the tasks list in the synchronized SharePoint site for the active project.

Syntax

expression. AddSiteColumn(ProjectField, SharePointName)

expression A variable that represents an Application object.

Parameters

NameRequired/OptionalData TypeDescription
ProjectFieldOptionalPjFieldCan be one of a subset of constants in the PjField enumeration, which specifies the project field to show in the new column; cannot be one of the prohibited fields (see Remarks).
SharePointNameOptionalVariantThe name of the new column.
ProjectFieldOptionalPJFIELD
SharePointNameOptionalVARIANT
NameRequired/OptionalData typeDescription

Return value

Boolean

True if the column is added.

Remarks

The AddSiteColumn method gives run-time error 1004, "Application-defined or object-defined error," in the following cases:

  • The active project is not associated with a synchronized SharePoint tasks list. If the project is local, you can use the LinkToTaskList method to create a synchronized SharePoint tasks list.

  • The column name already exists in the SharePoint tasks list. To see the list of column names, open the tasks list in SharePoint, and then choose Modify View on the LIST tab. The Settings ? Edit View page shows all of the column names that are available for the tasks list.

  • The ProjectField value is a non-task field, such as pjResourceActualCost. A SharePoint tasks list shows task fields, not resource fields.

  • The ProjectField value is an enterprise custom field such as pjTaskEnterpriseProjectText1, or a lookup table field such as pjTaskResourceEnterpriseRBS. Local task custom fields, such as pjTaskText1, are valid.

  • The ProjectField value is one of the prohibited fields in Table 1. These fields are in addition to the prohibited resource fields and enterprise custom fields. The fields are prohibited because they are related to other prohibited fields, or have value types that are not supported in a default SharePoint tasks list.

    Although Table 1 and the other prohibited fields may appear to be a long list, of the 1,338 constants in PjField, there are 357?including local task custom fields?that can be used with the AddSiteColumn method.

**Table 1. Additional prohibited fields**
pjTaskActivepjTaskActualOvertimeWorkpjTaskACWP
pjTaskAssignmentDelaypjTaskAssignmentPeakUnitspjTaskAssignmentUnits
pjTaskBaseline[1-10]BudgetCostpjTaskBaseline[1-10]BudgetWorkpjTaskBaseline[1-10]FixedCostAccrual
pjTaskBaselineBudgetCostpjTaskBaselineBudgetWorkpjTaskBaselineFixedCostAccrual
pjTaskBudgetCostpjTaskBudgetWorkpjTaskCalendarGuid
pjTaskConstraintDatepjTaskConstraintTypepjTaskCostRateTable
pjTaskDeliverableGuidpjTaskDeliverableTypepjTaskDemandedRequested
pjTaskEarnedValueMethodpjTaskEnterpriseOutlineCode[1-30]pjTaskExternalTask
pjTaskFinishSlackpjTaskFixedCostAccrualpjTaskFreeSlack
pjTaskGuidpjTaskHideBarpjTaskHyperlink
pjTaskHyperlinkAddresspjTaskHyperlinkHrefpjTaskHyperlinkScreenTip
pjTaskHyperlinkSubAddresspjTaskIDpjTaskIgnoreWarnings
pjTaskIndicatorspjTaskIsAssignmentpjTaskLevelAssignments
pjTaskLevelDelaypjTaskLinkedFieldspjTaskManual
pjTaskMilestonepjTaskNotespjTaskObjects
pjTaskOutlineCode[1-10]pjTaskOutlineLevelpjTaskOutlineNumber
pjTaskPathDrivenSuccessorpjTaskPathDrivingPredecessorpjTaskPathPredecessor
pjTaskPathSuccessorpjTaskPreleveledFinishpjTaskPreleveledStart
pjTaskPrioritypjTaskResourceTypepjTaskStartSlack
pjTaskStatuspjTaskStatusIndicatorpjTaskSubproject
pjTaskSubprojectReadOnlypjTaskTotalSlackpjTaskType
pjTaskWarningpjTaskWorkContour****

It is possible to add a field that already exists in the tasks list, if you use a unique name for the SharePointName parameter?although the value of doing so is questionable.

Example

To use the AddDurationColumns macro, create a tasks list in a SharePoint site, create a project in Project Professional, and then use the LinkToTaskList method to import the task list. Set a baseline for the active project by using the Set Baseline command on the PROJECT tab of the ribbon, and then change the duration of some tasks.

The AddDurationColumns macro adds task duration and baseline duration to the list of available columns in the SharePoint task list (see Figure 1).

Note After you run the AddDurationColumns macro, you must save the project in Project Professional to synchronize your changes with the SharePoint task list.

Sub AddDurationColumns()
    Dim success As Boolean
    Dim results As String
    Dim columnName As String
    Dim fieldName As PjField
    results = ""

    ' Add the first column.
    fieldName = pjTaskBaselineDurationText
    columnName = "Baseline duration"

    ' If the field name exists in the SharePoint tasks list, or fieldName
    ' is one of the prohibited fields, the AddSiteColumn method
    ' returns error 1100.
    On Error Resume Next

    success = AddSiteColumn(fieldName, columnName)

    If success Then
        results = "Added site column: " &; columnName
    Else
        results = "Error in AddSiteColumn: " &; columnName
    End If

    ' Add the second column.
    fieldName = pjTaskDurationText
    columnName = "Current duration"

    success = AddSiteColumn(fieldName, columnName)

    If success Then
        results = results &; vbCrLf &; "Added site column: " &; columnName
    Else
        results = results &; vbCrLf &; "Error in AddSiteColumn: " &; columnName
    End If

    Debug.Print results
End Sub

After you save the project, go to the task list in SharePoint. On the LIST tab, select the Modify View command. On the Settings - Edit View page, select the Baseline duration field and the Current duration field that the AddDurationColumns macro added. Figure 1 shows the task list with the two new fields.

Figure 1. Adding fields to a synchronized SharePoint task list

Adding fields to a synchronized tasks list

See also

Concepts

Application ObjectPjField Enumeration

Other resources

LinkToTaskList Method

© 2018 Microsoft