Check out my new blog at https://shibumiware.blogspot.com

Wednesday, February 20, 2008

LookupTableSortOrderMustComeAfterParentSortOrder

Microsoft Project Server 2007 errors codes are great because even though I Googled the known universe and found no useful documentation, I was able to understand that adding a text value to a custom field either requires one to set the index of the row or setup the lookup table to sort descending or ascending.

  image

public void AddLookupTableTextValue(string lookupTableGuid, string value)
{
    LookupTableMultiLangDataSet lookupTableDataSet = null;
    bool checkedOut = false;

    try
    {
        lookupTableDataSet = 
            _lookupTableWebService.ReadLookupTablesMultiLangByUids(new Guid[] {new Guid(lookupTableGuid)}, true);

        checkedOut = true;

        LookupTableMultiLangDataSet.LookupTableStructuresRow structureRow =
            lookupTableDataSet.LookupTableStructures.NewLookupTableStructuresRow();
        structureRow.LT_UID = new Guid(lookupTableGuid);
        structureRow.LT_STRUCT_UID = Guid.NewGuid();
        lookupTableDataSet.LookupTableStructures.Rows.Add(structureRow);

        LookupTableMultiLangDataSet.LookupTableValuesRow newValue =
            lookupTableDataSet.LookupTableValues.NewLookupTableValuesRow();

        newValue.LCID = 1033;
        newValue.LT_VALUE_TEXT = value;
        newValue.LT_STRUCT_UID = structureRow.LT_STRUCT_UID;
        newValue.LT_VALUE_SORT_INDEX = lookupTableDataSet.LookupTables[0].LT_SORT_ORDER_ENUM;
        lookupTableDataSet.LookupTableValues.AddLookupTableValuesRow(newValue);
        _lookupTableWebService.UpdateLookupTablesMultiLang(lookupTableDataSet, false, true);

        checkedOut = false;
    }

    #region Exception Handlers

    catch (SoapException soapException)
    {
        ProjectServer.ProcessMsProjectErrors(soapException, _errorsTextBox, _useEventLogging);
        ProjectServer.ProcessException(soapException.Message, soapException.InnerException, EventLogEntryType.Error);
        if (_continueOnError == false)
        {
            throw;
        }
    }
    catch (Exception exception)
    {
        ProjectServer.ProcessException(exception.Message, exception, EventLogEntryType.Error);
        if (_continueOnError == false)
        {
            throw;
        }
    }
    finally
    {
        if (lookupTableDataSet != null)
        {
            lookupTableDataSet.Dispose();
        }

        if (checkedOut)
        {
            try
            {
                _lookupTableWebService.CheckInLookupTables(new Guid[] {new Guid(lookupTableGuid)}, true);
            }
            catch
            {
                /*  Swallow  */
            }
        }
    }

    #endregion
}

No comments :

Disclaimer

Content on this site is provided "AS IS" with no warranties and confers no rights. Additionally, all content on this site is my own personal opinion and does not represent my employer's view in any way.