none
Unknown Error when trying to create a lookup table using CSOM and C# (Project Server 2013 Cloud - Office 365) RRS feed

  • Question

  • Hi,

    I have been trying for the last (almost) week, to create a lookup table in Project Server 2013 (Cloud based on Office 365) using CSOM and C#.

    I have been able to add entries to existing lookup tables, create custom fields and resources without any issues (using CSOM and C#).

    I have the problem when trying to create the Lookup Table using the LookupTableCreationInformation object.  I fill the properties (have tried various combinations) and attempt to add to the LookupTable objects.

    The error is raised when I run the ExecuteQuery() after preparing the objects.  The Error returned is "Unknown Error", with an error code -1.

    Example Code:
        List<LookupMask> masks = new List<LookupMask>();
        LookupMask mask1 = new LookupMask();
        mask1.Separator = ".";
        mask1.Length = 0;
        mask1.MaskType = LookupTableMaskSequence.CHARACTERS;
    
        masks.Add(mask1);
        
        LookupTableCreationInformation ltci = new LookupTableCreationInformation();                
    
        ltci.Id = Guid.NewGuid();
        ltci.Name = "MyLookupTable";
        ltci.Masks = masks;                
    
        ltci.SortOrder = LookupTableSortOrder.Ascending;
        
        LookupTable table = pContext.LookupTables.Add(ltci);
        pContext.LookupTables.Update();
        
        pContext.ExecuteQuery();
       
    Error Raised:

        Microsoft.SharePoint.Client.ServerException: Unknown Error
           at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
           at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
           at ProjectServer2013ExperimentApp.ProjectServer2013HelperClass.AddLookupTable(ProjectContext pContext, String lookupTableName) in z:\Project Server 2013 Cloud\ProjectServer2013ExperimentApp\ProjectServer2013ExperimentApp\ProjectServer2013HelperClass.cs:line 270
        
    Has anyone been able to successfully create a lookup table using the CSOM components?  Any advice or examples would be very much appreciated.

    Thanks in advance,

    Steve
    Thursday, May 23, 2013 11:08 AM

All replies

  • Hi Steve,

    Have you found the solution to this? I am facing the very same issue

    Thursday, October 17, 2013 2:00 PM
  • In addition, I haven't been able to find a way to specify "FieldType" for new lookup table.

    LookupTableCreationInformation Class doesn't have this property available.

    MSDN Documentation is very unhelpful

    Friday, October 18, 2013 4:11 AM
  • Hi Hammad,

    I racked my brain to solve this one recently for a project I'm working on. Gotta love the sparse documentation!

    Basically the code above is missing the Lookup Entries, which are required as they also actually specify what the Field Type is, here's a code snip it (in JSOM but the syntax is the same for CSOM) that should help:

    // Create the Lookup Table Entries
    var entries = [];
    for (var e = 0; e < selectedData[i].Entries.length; e++) {
    	var ltEntry = new PS.LookupEntryCreationInformation();
    
    	ltEntry.set_description(selectedData[i].Entries[e].Description);
    	ltEntry.set_sortIndex(selectedData[i].Entries[e].SortIndex);
    
    	var id = guid();
    	ltEntry.set_id(id);
    
    	// Save the GUID in our Object for use in the Parent property of future entries
    	selectedData[i].Entries[e].Id = id;
    
    	if (!!selectedData[i].Entries[e].Parent) {
    
    		var parent = $.grep(selectedData[i].Entries, function (obj) {
    			return obj.FullValue === selectedData[i].Entries[e].Parent.FullValue;
    		});
    
    		ltEntry.set_parentId(parent[0].Id);
    	}
    	else {
    		ltEntry.set_parentId(null);
    	}
    
    
    	var ltValue = new PS.LookupEntryValue();
    
    	switch (selectedData[i].FieldType) {
    		case (PS.CustomFieldType.TEXT):
    			ltValue.set_textValue(selectedData[i].Entries[e].Value);
    			break;
    		case (PS.CustomFieldType.COST):
    			ltValue.set_numberValue(selectedData[i].Entries[e].Value);
    			break;
    		case (PS.CustomFieldType.DURATION):
    			ltValue.set_durationValue(selectedData[i].Entries[e].Value);
    			break;
    		case (PS.CustomFieldType.DATE):
    			ltValue.set_dateValue(selectedData[i].Entries[e].Value);
    			break;
    	}
    	ltEntry.set_value(ltValue);
    
    	entries.push(ltEntry);
    }
    newLT.set_entries(entries);

    HTH,


    Martin Laukkanen (Project Server Blog - www.nearbaseline.com/blog)

    • Proposed as answer by Hammad Arif Sunday, October 27, 2013 8:32 AM
    Wednesday, October 23, 2013 1:14 AM
  • Hay martin,

    Thanks Mate.

    tried it today and it worked like a Charm :)

    Sunday, October 27, 2013 8:34 AM