Loading...

Monday, August 27, 2012

Updating lookup table in Project server 2010

Following is the code snippet for updating lookup table value in project server 2010

using PSLibrary = Microsoft.Office.Project.Server.Library;
using Updatelookup.WebSvcLookup;
using System.Net;
using System.Data;

namespace Updatelookup
{

class Program
{

static void Main(string[] args)

{
LookupTable tblLookup = new LookupTable();
tblLookup.Url = "pwaurl" + "/" + "_vti_bin/PSI/LookupTable.asmx";
NetworkCredential prjCdn = new NetworkCredential("user", "pwd", "domain");
tblLookup.Credentials = prjCdn;

AddToLookupTB(tblLookup, "Customer");

}


static void AddToLookupTB(LookupTable tblLookup, string TableName)

{
LookupTableDataSet lookupDs = new LookupTableDataSet();

//Get all the lookup table

//Get lookup table guid
lookupDs = tblLookup.ReadLookupTables("", false, 0);//
DataView dvLookup = new DataView(lookupDs.Tables["LookupTables"]);
dvLookup.RowFilter = "LT_Name = '" + TableName + "'";
DataTable lookupValueTB = new DataTable();

lookupValueTB = dvLookup.ToTable("LookupTable");
Guid LookupgId = new Guid(Convert.ToString(lookupValueTB.Rows[0]["LT_UID"]));

//Read lookup table dataset
Guid[] ltGuids = new Guid[] { LookupgId };
LookupTableDataSet LTCustomer = tblLookup.ReadLookupTablesByUids(ltGuids, false, 1033);
LookupTableDataSet.LookupTableTreesRow drLT_TREE = LTCustomer.LookupTableTrees.NewLookupTableTreesRow();

//Add new lookup value
drLT_TREE.LT_UID = LookupgId;
drLT_TREE.LT_STRUCT_UID = Guid.NewGuid();
drLT_TREE.SetLT_PARENT_STRUCT_UIDNull();
drLT_TREE.LT_VALUE_TEXT = "Customer 3";
drLT_TREE.LT_VALUE_SORT_INDEX = (byte)PSLibrary.LookupTables.SortOrder.Descending;
( here I checked the orginal order of values in lookup table by Navigating server settings--> Lookup table-->Customer lookup table and made ensure that order given there and in mentioned in above code line is same .)
LookupTableDataSet newLTDs = LTCustomer.GetChanges() as LookupTableDataSet;

tblLookup.CheckOutLookupTables(ltGuids);
tblLookup.UpdateLookupTables(newLTDs, false, false, 1033);
tblLookup.CheckInLookupTables(ltGuids, false);

}}}

No comments: