Reputation: 6648
How do you set the value of DocumentShowInSiteMap
property in Kentico?
I've tried:
DocumentHelper
and TreeHelper
apis but with both, this property doesn't give you access to the setter.dbo.CMS_Document.DocumentShowInSiteMap
to 1
and 0
. These queries run fine but when I go to the pages app, there is no change in the 'Show in sitemap' property checkbox, ie. setting the database field to 0 doesn't 'untick' this checkbox.I'm trying to run a scheduled task which will set this property for documents at a specified location automatically. What is the proper way to do this? Any help appreciated.
Upvotes: 0
Views: 239
Reputation: 6648
Trevor J Fayas's answer would probably work. I figured this out yesterday and just leaving my solution here just in case:
TreeHelper
.GetDocuments(task.CurrentSiteName, aliaspath, null, false, "", "", "", -1, false, -1)
.Where(doc => doc.DocumentShowInSiteMap)
.ToList()
.ForEach(node =>
{
node.SetValue("DocumentShowInSiteMap", false);
node.Update();
});
Obviously replace aliaspath
with the one you need or use DocumentHelper.GetDocuments
which takes different parameters.
Upvotes: 0
Reputation: 1437
Have you tried this?
int TheDocumentToModify = 1221;
var PageItem = DocumentHelper.GetDocument(TheDocumentToModify , new TreeProvider());
foreach(var culturePage in PageItem.CultureVersions)
{
culturePage.SetValue("DocumentShowInSiteMap", true);
// May need to apply Workflow check in / check out, see Kentico API examples based on your need.
culturePage.Update();
}
Upvotes: 1
Reputation: 511
Within code, there is no simple way. Setter should be available within special class DocumentCultureDataInfo and it should be saved with SetObject. This class contains all of culture DB fields and is manipulated by DocumentCultureDataInfoProvider.
This class is an internal property of TreeNode. However I have not tried doing this arbitrary in code and mentioned classes are part of innner API.
Your second approach should work, but documents and their properties are cached and you will need to refresh cache so that new DB value is actually picked up Loading of this property goes through simple GetData in LoadDefaultValues for each TreeNode.
Upvotes: 0