Question

For example, I have two lists: Users (Login, Password) and Profiles (Phone number, Email). So we have users and related info in their profiles.

Now I want to create another view for users, that combines info from these lists. So i want to display Login|Password|Phone|Email in TotalUsersInfoView - default view of Users list. I wrote this, but it doesn't work as expected. I get #Err lines in allrelated columns instead of data except one.

So i have 3 columns: TaxonomyFieldType,Text and URL. Text lookup works fine but others doesn't.

Code:

private void AddFields(SPList measuresList, SPList investList)
{
    foreach (string staticName in FieldsToAdd)
    {                
        TryAddField(measuresList, investList, staticName);
    }
}

private static void TryAddField(SPList measuresList, SPList investList, string staticName)
{
    string measureFieldStaticName = GetFieldName(staticName);
    if (measuresList.Fields.ContainsFieldWithStaticName(measureFieldStaticName))
    {
        var lookup = measuresList.Fields.TryGetFieldByStaticName(measureFieldStaticName);
        if (!measuresList.DefaultView.ViewFields.Exists(lookup.InternalName))
        {
            AddToView(measuresList.DefaultView, lookup);
        }
    }
    else
    {
        var investField = investList.Fields.TryGetFieldByStaticName(staticName);
        var rootField = measuresList.Fields.TryGetFieldByStaticName(RootLookupName);

        string internalName = measuresList.Fields.AddDependentLookup(investField.Title, rootField.Id);
        var lookup = (SPFieldLookup)measuresList.Fields.GetFieldByInternalName(internalName);
        lookup.StaticName = measureFieldStaticName;
        lookup.LookupField = investField.InternalName;
        lookup.Update();

        AddToView(measuresList.DefaultView, lookup);
    }
}

private static void AddToView(SPView view, SPField field)
{
    view.ViewFields.Add(field);
    view.Update();  
}

Result:

enter image description here

Was it helpful?

Solution

Okay, I got it: only text and primitive types are allowed to be lookuped by standard mechanism. You should write your own "fixer" to achieve needed behaviour.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top