Delete Existing Lookup Entry from Lookup Table using PSI Project Server 2013

Delete Existing Lookup Entry from Lookup Table using PSI Project Server 2013. Manually we can Delete Existing Lookup Entry from Lookup Table. In case if we need to delete existing lookup entry from LookupTable programmatically then we need to write code.

Below is code to Delete Existing Lookup Entry from Lookup Table using PSI Project Server 2013.

If you don’t know how to PSI service reference in solution, Follow my post Add PSI Web Reference in Solution file

 public string DeleteLookupTableEntry(string LookupTableGuid , string LookupEntry)
        {
            string result = "";
           
            string tableName = "[unknown]";
           lookupSVC.LookupTableDataSet lutDs = new lookupSVC.LookupTableDataSet();
            

            if (!string.IsNullOrEmpty(GUID ))
            {
                LookupTableGuid = new Guid(LookupTableGuid);

               
                lookupTableWS = new lookupSVC.LookupTable { Credentials = System.Net.CredentialCache.DefaultCredentials, Url = string.Format("{0}{1}", PWAPath, "/_vti_bin/PSI/LookupTable.asmx") };




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

            lutDs = lookupTableWS.ReadLookupTablesByUids(lutList, autoCheckOut, 1033);
            int numRows = lutDs.LookupTableTrees.Rows.Count;

            foreach (DataRow lutRow in lutDs.LookupTables)
            {
                if ((Guid)lutRow[lutDs.LookupTables.LT_UIDColumn] == LookupTableGuid)
                {
                    tableName = (string)lutRow[lutDs.LookupTables.LT_NAMEColumn];
                    break;
                }
            }
            int i = 0;
            foreach (DataRow  dr in lutDs.LookupTableTrees.Rows)
            {
                if (Convert.ToString(dr["LT_VALUE_TEXT"]) == LookupEntry)
                {
                    lutDs.LookupTableTrees.Rows[i].Delete();

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

                  
                   
                    break;
                }
                i++;
            }
            }
            return result;
        }

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!