Sitecore GetChildren empty just after child item created

2.4k views Asked by At

I have a Sitecore.Services.Client API controller wired up to a Sitecore SPEAK application that uploads a media item (CSV) then parses the CSV and imports the data.

Once this import is complete I create a summary item within Sitecore that contains a list of items created, any errors, a link to the CSV uploaded.

var parentItem = _itemReader.GetItem(ParentItemId);
var template = _itemReader.GetTemplateItem(TemplateId);

var newItem = parentItem.Add(title, template);

I then have another controller that looks at the summary item folder get the children where the media ID is the item I have uploaded.

summaryFolder.Children.Where(x => x["Media file"] == mediaItemId).FirstOrDefault();

The issue i'm seeing is that once the one controller has created the item, the next controller is calling Item.Children however no children are found. If i request the controller again later they are found. It appears like the Item cache potentially or something similar isn't updating in time.

Is there anyway to request an item bypassing any caching and go directly to the database. Or is there anyway when i create the item to force the cache to update?

Full code

public ImportAudit GetLatestAudit(string mediaItemId)
{
        var importAudit = new ImportAudit();

        var summaryFolder = masterDatabase.GetItem(new ID(AuditFolderId));

        if (summaryFolder != null)
        {
            var lastestAudit = summaryFolder.GetChildren().Where(x => x["Media file"] == mediaItemId).OrderByDescending(x => x.Statistics.Created).FirstOrDefault();

            if (lastestAudit != null)
            {
                importAudit.ImportedItems = GetTitles(lastestAudit, "Imported Items");
            }
        }

        return importAudit;
    }
1

There are 1 answers

0
Komainu85 On BEST ANSWER

This fixed by a suggestion by Mark Cassidy, this was due to the call order of the JavaScript hitting the wrong controller first.