LookupTable.UpdateLookupTables Method

Creates, modifies, or deletes data in custom field lookup tables. UpdateLookupTables creates lookup tables and corresponding code masks if the LookupTableDataSet includes new lookup tables, modifies existing lookup tables, and deletes lookup tables that are not in the LookupTableDataSet.

Namespace:  [LookupTable Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/LookupTable.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/LookupTable.asmx?wsdl

[SoapDocumentMethodAttribute("http://schemas.microsoft.com/office/project/server/webservices/LookupTable/UpdateLookupTables", RequestNamespace = "http://schemas.microsoft.com/office/project/server/webservices/LookupTable/", 
	ResponseNamespace = "http://schemas.microsoft.com/office/project/server/webservices/LookupTable/", 
	Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void UpdateLookupTables(
	LookupTableDataSet ltds,
	bool validateOnly,
	bool autoCheckIn,
	int language
)

Parameters

ltds
Type: [LookupTable Web service].LookupTableDataSet
LookupTableDataSet with data in the datatables.
validateOnly
Type: System.Boolean
Validate only, do not update.
autoCheckIn
Type: System.Boolean
If true, check in after update.
language
Type: System.Int32
Locale ID (LCID).

UpdateLookupTables updates data in existing lookup tables. To create or delete lookup tables, you can also use CreateLookupTables and DeleteLookupTables.

To delete a lookup table value, first use the ReadLookupTablesByUids method to get a complete LookupTableDataSet, and then use the LookupTableDataSet.LookupTableTrees.Rows[index].Delete method, which marks the row for deletion. See the Example section.

To update one or more lookup tables, use ReadLookupTablesByUids to get all of the data tables necessary for each lookup table, and then modify the returned LookupTableDataSet to use for the ltds parameter in UpdateLookupTables.

You can also use ReadLookupTables with a null reference (Nothing in Visual Basic) for the xmlFilter parameter. In the following example, lookupTable is an instance of the LookupTableWebService.LookupTable class, and lookupTableDataSet is an instance of a LookupTableDataSet.

bool autoCheckOut = false;
string xmlFilter = null;
int language = 0;
lookupDataSet = lookupTable.ReadLookupTables(xmlFilter, autoCheckOut, language);
// Add, delete, or modify lookup table rows 
bool validateOnly = false;
autoCheckOut = true;
lookupTable.UpdateLookupTables(lookupTableDataSet, validateOnly, autoCheckOut, language);
// Call lookupTable.CheckInLookupTables
NoteNote

If you use ReadLookupTables and specify xmlfilter values, you may not get all of the tables necessary for an update. In that case, UpdateLookupTables results in a general unhandled exception.

Caution noteCaution

When you use the PSI to create or update a number lookup table, do not add values that have more than two decimal places.

The UpdateLookupTables method enables you to save a number with more than two decimal places. When you create a custom field that uses the number lookup table, Project Professional 2010 rounds the number custom field values to two decimal places and shows them as strings in the drop-down list to select a value. When you select a value, Project Professional 2010 converts the string back to a number. The process shows an error, because the numeric value with only two decimal places does not exist.

Project Server Permissions

Permission

Description

ManageEnterpriseCustomFields

Allows the user to modify the definitions of enterprise custom fields and lookup table values. Global permission.

The following example reads a specified lookup table and deletes a specified row in the table. The lookupTable parameter in the DeleteLookupTableRow sample method is a LookupTable object with valid Url and Credentials properties. The language parameter is an integer for the LCID; for example, 1033 is U.S. English. LookupTableWebSvc is an arbitrary reference name to the LookupTable.asmx Web service. For more information about using the code sample, see Prerequisites for ASMX-Based Code Samples.

public string DeleteLookupTableRow(LookupTableWebSvc.LookupTable lookupTable,
    Guid lutGuid, int row, int language)
{
    string result = "";
    string fmtResult = "Lookup table: {0}. ";
    string tableName = "[unknown]";
    string rowName = "";

    LookupTableWebSvc.LookupTableDataSet lutDs = new LookupTableWebSvc.LookupTableDataSet();

    Guid[] lutList = new Guid[] { lutGuid };
    bool autoCheckOut = false;

    lutDs = lookupTable.ReadLookupTablesByUids(lutList, autoCheckOut, language);
    int numRows = lutDs.LookupTableTrees.Rows.Count;

    foreach (DataRow lutRow in lutDs.LookupTables)
    {
        if ((Guid)lutRow[lutDs.LookupTables.LT_UIDColumn] == lutGuid)
        {
            tableName = (string)lutRow[lutDs.LookupTables.LT_NAMEColumn];
            break;
        }
    }

    if (row < numRows)
    {
        rowName = lutDs.LookupTableTrees[row].LT_VALUE_TEXT;
        lutDs.LookupTableTrees.Rows[row].Delete();

        lookupTable.CheckOutLookupTables(lutList);
        bool validateOnly = false;
        lookupTable.UpdateLookupTables(lutDs, validateOnly, autoCheckOut, language);
        bool forceCheckIn = false;
        lookupTable.CheckInLookupTables(lutList, forceCheckIn);

        fmtResult += "Row {1} deleted: {2}";
        result = string.Format(fmtResult, tableName, row, rowName);
    }
    else
    {
        fmtResult += "Requested row {1} greater than number of rows {2}.";
        result = string.Format(fmtResult, tableName, row, numRows);
    }
    return result;
}

Reference

Other Resources

Walkthrough: Creating a Hierarchical Lookup Table

Community Additions

Show:
© 2014 Microsoft