I want to set a General Field (Simple Text Field) on a Component to specific word (ex. "aaa") when the Component is saved, by using Event System.
I success to do the above, but I have one problem.
If the General Field is not Mandatory, it's no problem.
But if the General Field is Mandatory, it's problem, that is, the component isn't saved because of displaying error message "Mandatory field "xxx" is missing a value".
One solution is I set the General Field to not Mandatory.
But I want to set the General Field to Mandatory.
So please tell me a solution, that is,
how to set a General Field to specific word before SDL Tridion check whether the General Field is missing a value or not, using event system.
UPDATE2
the below code is my code.
private void Subscribe()
{
EventSubscription subScription = EventSystem.Subscribe<Component, SaveEventArgs>(copys, EventPhases.Initiated);
_subScriptions.Add(subScription);
}
private void copys(Component component, SaveEventArgs args, EventPhases phases)
{
if (!component.Schema.Title.Equals("copy_test")) return;
ItemFields generalFields = new ItemFields(component.Content, component.Schema);
foreach (ItemField child in generalFields)
{
if (child.Name=="copy")
{
TextField text = (TextField)child;
text.Value = "set the value";
}
}
component.Content = generalFields.ToXml();
}