I have to check that the item has the field "In training", if that field exists and is different from 1, I have to set it to 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");
}
}
I am aware that I have written nonsense, so I ask for support
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");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.