我必须检查项目是否有字段"In training",如果该字段存在并且与1不同,我必须将其设置为1。
var field = "In Allenamento";
var value = "0";
var edited = (field = "1");
if (field != null && field == value)
{
field = "1";
}
using (new Sitecore.SecurityModel.SecurityDisabler())
{
item.Editing.BeginEdit();
item.Fields[field].Value = field;
item.Editing.EndEdit();
log.AppendLine(item.ID + "edited");
}
}
我知道我写了些废话,所以我请求支持
- 按字段名("In Allenamento"或"在培训中">
- 如果字段为空,则表示该项不存在
- 检查其值是否为"1">
- 开始编辑
- 更新值
- 结束编辑
using (new Sitecore.SecurityModel.SecurityDisabler())
{
var inTrainingField = item.Fields["In Allenamento"];
if (inTrainingField != null && inTrainingField.Value != "1")
{
item.Editing.BeginEdit();
item.Fields["In Allenamento"].Value = "1";
item.Editing.EndEdit();
log.AppendLine(item.ID + "edited");
}
}