0

Is there a way to dynamically change the value of a Template field in Sitecore based on other template field selected value.

For example, let's say we have a template that has the following fields:

State (Type drop list)

Link (Link)

Expectation is : when to state field is selected , update the Link field value with selected state name as query string parameter

I understand On ItemSave is one way, wanted to know is it possible using token/field

1
  • If you must update the field value, as the answers have stated, you will need to use the onItemSaved event. But Peters answer is more accurate, its not a good idea to do this. Just have the fields saved as they are and build the link in the rendering of the component.
    – Richard Seal
    Feb 12 at 16:40

3 Answers 3

2

I don't think it is possible using token because token will allow us to dynamically add values to fields, according to the item that is being created by the Content Author.

So you can create your own ItemSave handler which will change this field for particular item templates.

You can follow below link for more details.

How to change Sitecore field value based on another field(s)

Hope this helps.

2

I wouldn't recommend changing link field value while changing Item State field. Better is to concatenate / generate link on FE side. You have both values passing to FE so it shouldn't be a problem to use State value together with Link to generate proper link at the end...

1

Sitecore tokens can be used to dynamically add values to fields when creating an item. But in your case, I guess you are working with already created items.

So you are right, the item save event will be used for this.

You can use something like this.

    public void OnItemSaved(object sender, EventArgs args)
    {
        Item item = Event.ExtractParameter(args, 0) as Item;
        if (item != null && item.Database.Name.ToLower() == Master)
        {
            if (item.TemplateID.ToString() == TemplateIdItem )
            {
                item.Editing.BeginEdit();
                
               //update your field value.

                item.Editing.EndEdit();
                item.Editing.AcceptChanges();
            }
        }
    }

And create a patch file to add events.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.