Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing properties of TOM.NET objects when passing them between methods after GetItems(filter) call

We're facing a strange issue when using the GetItems method and passing each item within the returned collection to another method.

We are on Tridion 2011 GA.

The following the code is breaking:

private void foo(StructureGroup structureGroup, Session session, int counterTemp, int levels)
{
    OrganizationalItemItemsFilter filtersg= new OrganizationalItemItemsFilter(session);
    filtersg.Recursive = false;
    IEnumerable<ItemType> itemtype = new List<ItemType> { ItemType.StructureGroup};
    filtersg.ItemTypes = itemtype;

    foreach (StructureGroup sg in structureGroup.GetItems(filtersg))
    {
        GetSiteMap(sg, counterTemp, levels);
    }
}

private void GetSiteMap(StructureGroup sg, int counter, int levels)
{
    logger.Info(sg.Id);  //ok
    logger.Info(sg.Title);  //ok
    logger.Info(sg.Directory);  // null !?
}

However, if the sg.Directory is access prior to passing sg into the next method, all works fine:

private void foo(StructureGroup structureGroup, Session session, int counterTemp, int levels)
    OrganizationalItemItemsFilter filtersg= new OrganizationalItemItemsFilter(session);
    filtersg.Recursive = false;
    IEnumerable<ItemType> itemtype = new List<ItemType> { ItemType.StructureGroup};
    filtersg.ItemTypes = itemtype;

    foreach (StructureGroup sg in structureGroup.GetItems(filtersg))
    {
        logger.Info(sg.Directory); //if printed here, all works fine down the line.
        GetSiteMap(sg, counterTemp, levels);
    }
}

private void GetSiteMap(StructureGroup sg, int counter, int levels)
{
    logger.Info(sg.Id);  //ok
    logger.Info(sg.Title);  //ok
    logger.Info(sg.Directory);  // ok   }
}

It feels that there is something going on with the GetItems() method where it doesn't return the full object, and once passing the partially loaded object to the next method, it's not able to load the properties as if the original reference is lost.

Can someone please shed some light on what's happening here? Also, is it bad to pass TOM.NET objects between methods?

Thanks

like image 288
Nickoli Roussakov Avatar asked Oct 07 '22 05:10

Nickoli Roussakov


1 Answers

That seems really weird - in fact I cannot reproduce on 2011 GA - I pasted your functions into a .NET TBB and executed from the template builder - both methods output the directory just fine. This probably wont work as its pure guesswork, but a couple of things to try:

  1. filter.BaseColumns = ListBaseColumns.Extended - I think this is just for GetListItems, but you never know...
  2. try outputting the sg.LoadState to see if its somehow not fully loaded

If all else fails, use GetListItems, and then create a StructureGroup object for every item that you want to process (presuming that you will skip some SGs from the sitemap based on sg.Title). Its a bit of a shame that there is no url attribute for the data returned from GetListItems, otherwise you could do it all in one go with Publication.GetListItems(), with a recursive filter for SGs only (or SGs and Pages).

like image 174
Will Avatar answered Oct 10 '22 01:10

Will