Skip to main content
Tweeted twitter.com/#!/StackTridion/status/480255561846386688
deleted 366 characters in body
Source Link
Arai Yuhei
  • 961
  • 4
  • 10

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 readonly List<EventSubscription> _subScriptions = new List<EventSubscription>();
    public copy() 
    {
        Subscribe();
    }

    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();
    }

    public void Dispose()
    {
        foreach (EventSubscription subscription in _subScriptions)
        {
            subscription.Unsubscribe();
        }
    }

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 readonly List<EventSubscription> _subScriptions = new List<EventSubscription>();
    public copy() 
    {
        Subscribe();
    }

    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();
    }

    public void Dispose()
    {
        foreach (EventSubscription subscription in _subScriptions)
        {
            subscription.Unsubscribe();
        }
    }

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();
    }
added 4 characters in body
Source Link
Arai Yuhei
  • 961
  • 4
  • 10

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 readonly List _subScriptions = new List(); public copy() { Subscribe(); }

private readonly List<EventSubscription> _subScriptions = new List<EventSubscription>();
    public copy() 
    {
        Subscribe();
    }

    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();
    }

    public void Dispose()
    {
        foreach (EventSubscription subscription in _subScriptions)
        {
            subscription.Unsubscribe();
        }
    }

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 readonly List _subScriptions = new List(); public copy() { Subscribe(); }

    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();
    }

    public void Dispose()
    {
        foreach (EventSubscription subscription in _subScriptions)
        {
            subscription.Unsubscribe();
        }
    }

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 readonly List<EventSubscription> _subScriptions = new List<EventSubscription>();
    public copy() 
    {
        Subscribe();
    }

    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();
    }

    public void Dispose()
    {
        foreach (EventSubscription subscription in _subScriptions)
        {
            subscription.Unsubscribe();
        }
    }
added 1042 characters in body
Source Link
Arai Yuhei
  • 961
  • 4
  • 10

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.

UPDATEUPDATE2

the below code is a part of all my code.

private readonly List _subScriptions = new List(); the EventPhases is initiated.public copy() { Subscribe(); }

    private void Subscribe()
    {
        EventSubscription subScription = EventSystem.Subscribe<Component, SaveEventArgs>(copycopys, 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();
    }

    public void Dispose()
    {
        foreach (EventSubscription subscription in _subScriptions)
        {
            subscription.Unsubscribe();
        }
    }

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.

UPDATE

the below code is a part of all my code. the EventPhases is initiated.

EventSubscription subScription = EventSystem.Subscribe<Component, SaveEventArgs>(copy, EventPhases.Initiated);

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 readonly List _subScriptions = new List(); public copy() { Subscribe(); }

    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();
    }

    public void Dispose()
    {
        foreach (EventSubscription subscription in _subScriptions)
        {
            subscription.Unsubscribe();
        }
    }
added 209 characters in body
Source Link
Arai Yuhei
  • 961
  • 4
  • 10
Loading
Source Link
Arai Yuhei
  • 961
  • 4
  • 10
Loading