locked
How to create a Custom Field that Looksup values from a Sharepoint List or External List RRS feed

  • Question

  • I need to add a custom Field "Project Code"  at Project Level that Looks up List of Project Code from an External Data List ( ERP Finance Module database)

    I also neet to add a validation that user get a warning if there is  any other Project in Project server with Same  Project .. so this becomes a Unique value in Project Center Views.

    Tuesday, January 31, 2012 6:09 PM

Answers

  • Hello greema,

    here is an example method of how to write data into a Project Server lookup table. You pass the following parameters to this method:

    • the Guid of the lookup table
    • the entries to write in as Dictionary<string, string>, where the keys are the values of the lookup table and the values of the dictionary the description texts.

     

    public void AddValuesToLookupTable(Guid lookupTableGuid, Dictionary<string, string> lookupTableValueDict)
    {
    
    	IList<PSLookupValueInfo> lookupValueInfoList = lookupTableService.GetLookupTableValueInfos(lookupTableGuid, typeof(string));
    
    	foreach (string key in lookupTableValueDict.Keys)
    	{
    		var existingLookupTableValue = (from p in lookupValueInfoList
    									 where p.FullValue == key
    									 select p).FirstOrDefault<PSLookupValueInfo>();
    
    		if (existingLookupTableValue == null)
    		{
    			PSLookupValueInfo lookupValueInfo = new PSLookupValueInfo();
    			lookupValueInfo.Uid = Guid.NewGuid();
    			lookupValueInfo.Data = key;
    			lookupValueInfo.FullValue = key;
    			lookupValueInfo.Description = lookupTableValueDict[key];
    			lookupValueInfoList.Add(lookupValueInfo);
    		}
    		else
    		{
    			existingLookupTableValue.Description = lookupTableValueDict[key];
    		}
    	}
    
    	lookupTableService.AddLookupTableValues(lookupTableGuid, lookupValueInfoList);
    }
    

    lookupTableService is the client proxy object to the Lookup table service of FluentPS. Whenever working with PSI I recommend using FluentPS (http://fluentps.codeplex.com). This is a kind of OR-Mapper for PSI, which makes it a lot more easier to code against PSI (e.g. you can model your project as a class including your Custom Fields and have a type-save access to all properties/custom fields).

    Hope this helps.
    Regards,
    Ronny


    • Edited by ronny_kl Friday, February 3, 2012 7:37 AM
    • Proposed as answer by Kashif Nizam Friday, February 3, 2012 10:53 PM
    • Marked as answer by Greema Thursday, February 21, 2013 9:03 AM
    Friday, February 3, 2012 7:37 AM

All replies

  • Sorry this is not possible through out of the box. You've to do custom coding using PSI.

    For your second solution, you've have to capture event of project create and check if the selected value is already used or not. If yes, show proper message to the user.

     


    Thanks, Kashif
    • Edited by Kashif Nizam Wednesday, February 1, 2012 11:49 AM
    Wednesday, February 1, 2012 11:46 AM
  • Hi,

    you can create a timer job or an event receiver (attached to the SharePoint list) to sync entries from the SharePoint list into a lookup table (which then is used to populate your "Project Code" field).

    Regarding the validation: I think it can be done using Javascript, but it might be tricky to use that odd PSI with Javascript. Or you create a server side event handler. Depends on where the validation warning should be shown.

    Regards,

    Ronny

    Thursday, February 2, 2012 6:42 AM
  • Thanks Ronny, how can I sync sharepoint List with the LookupTable of Project Server . Any example / code sample accessing Lookup table and populating it with values  would help.

    Regards,

    Greema

    Thursday, February 2, 2012 7:46 AM
  • You can look at the following link, the past tells you how to create lookup table using PSI.

    http://msdn.microsoft.com/en-us/library/ms486189.aspx

    For reading SharePoint list data.

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/e3225ad4-75e6-4d78-b0ee-1b8e566778fc/

    Hope this helps you out.


    Thanks, Kashif
    Thursday, February 2, 2012 7:46 PM
  • Hello greema,

    here is an example method of how to write data into a Project Server lookup table. You pass the following parameters to this method:

    • the Guid of the lookup table
    • the entries to write in as Dictionary<string, string>, where the keys are the values of the lookup table and the values of the dictionary the description texts.

     

    public void AddValuesToLookupTable(Guid lookupTableGuid, Dictionary<string, string> lookupTableValueDict)
    {
    
    	IList<PSLookupValueInfo> lookupValueInfoList = lookupTableService.GetLookupTableValueInfos(lookupTableGuid, typeof(string));
    
    	foreach (string key in lookupTableValueDict.Keys)
    	{
    		var existingLookupTableValue = (from p in lookupValueInfoList
    									 where p.FullValue == key
    									 select p).FirstOrDefault<PSLookupValueInfo>();
    
    		if (existingLookupTableValue == null)
    		{
    			PSLookupValueInfo lookupValueInfo = new PSLookupValueInfo();
    			lookupValueInfo.Uid = Guid.NewGuid();
    			lookupValueInfo.Data = key;
    			lookupValueInfo.FullValue = key;
    			lookupValueInfo.Description = lookupTableValueDict[key];
    			lookupValueInfoList.Add(lookupValueInfo);
    		}
    		else
    		{
    			existingLookupTableValue.Description = lookupTableValueDict[key];
    		}
    	}
    
    	lookupTableService.AddLookupTableValues(lookupTableGuid, lookupValueInfoList);
    }
    

    lookupTableService is the client proxy object to the Lookup table service of FluentPS. Whenever working with PSI I recommend using FluentPS (http://fluentps.codeplex.com). This is a kind of OR-Mapper for PSI, which makes it a lot more easier to code against PSI (e.g. you can model your project as a class including your Custom Fields and have a type-save access to all properties/custom fields).

    Hope this helps.
    Regards,
    Ronny


    • Edited by ronny_kl Friday, February 3, 2012 7:37 AM
    • Proposed as answer by Kashif Nizam Friday, February 3, 2012 10:53 PM
    • Marked as answer by Greema Thursday, February 21, 2013 9:03 AM
    Friday, February 3, 2012 7:37 AM