ahwm
11/25/2024, 7:23 PMp.GetValue("mainContent")
returns null.
I found [this forum post](https://our.umbraco.com/forum/using-umbraco-and-getting-started/112682-work-with-blocklist-properties-using-the-umbraco-content-service-v12) but the content.GetValue("content").ToString()
line is where I'm having trouble. Any insight?Chancer
11/25/2024, 7:39 PMcsharp
var query = serviceScope.ServiceProvider.GetRequiredService<IPublishedContentQuery>();
var allNodes = query.ContentAtRoot().SelectMany(x => x.DescendantsOrSelf());
foreach (var node in allNodes)
{
var sectionPicker = node.Value<IEnumerable<BlockListItem>>("sectionPicker");
var contentNode = _contentService.GetById(node.Id);
var jsonValue = contentNode.GetValue("sectionPicker").ToString();
BlockValue blockValue = JsonConvert.DeserializeObject<BlockValue>(jsonValue);
foreach (var column in blockValue.SettingsData)
{
foreach (var columnProperty in column.RawPropertyValues.ToList())
{
// Detect and edit the particular property value here.
}
}
}
//In our case, sectionPicker was the block list
Happy to send the full file for what we were updating (we were migrating a color picker property to a contentment data list. But might have some useful stuff for you).ahwm
11/25/2024, 7:55 PMserviceScope
? Your excerpt didn't include its type/definition 🙂Chancer
11/25/2024, 9:39 PMcsharp
using var _ = _umbracoContextFactory.EnsureUmbracoContext();
using var serviceScope = _serviceProvider.CreateScope();
My apologies 😄Chancer
11/25/2024, 9:39 PMahwm
11/25/2024, 9:47 PMGetValue<BlockValue>()
returning null. After digging through the object a bit, I came up with this:
var main = p!.Properties.First(x => x.Alias == "mainContent").Values.First().PublishedValue!.ToString()!;
ahwm
11/25/2024, 9:47 PM