Developer forum

Forum » CMS - Standard features » Item type - set value of one field to value of another field in same item?

Item type - set value of one field to value of another field in same item?

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Proably a Long Shot, but here goes

For an itemtype containing several fields, is it possible to "mirror" the value of one field to another field?

Let us say that we have 2 fields. One is a free text field, where you can enter a number between 0 and 2000.

The other field is a dropdown field, where you can select between 2000 options. Each of these 2000 options has a Label consisting of text, and a value consisting of number between 0 and 2000

 

any way of entering the number in field a and then show the name in field b, based on the relation between the matching numbers?

In backend that is. Not frontend.

Hope this makes some sort of sense?

Basically what I ask is, is there any way of two fields in an item "interacting" with each other?

 

/Hans

 


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Hans,

 

Are you asking for an interaction in the backend, or upon Saving?

 

BR

Nuno Aguiar

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Nuno

thanks for your reply 👍🏻 On saving would be fine.

Does this require a custom solution? Or would this be possible to do in a "standard solution"? If so, can you ellaborate a little on where I would do the coding? This can not be achieved through a razor template, right?

/Hans

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Hans,

 

You'd have to build a custom dll, as there is nothing in the backend that allows you to configure this. Here's an example

 

using Dynamicweb.Notifications;
using Dynamicweb.Extensibility.Notifications;

namespace MyProject
{
    [Subscribe(ItemNotification.Saving)]
    public class ItemSaving : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            if (!(args is ItemNotification.ItemArgs itemArgs))
            {
                return;
            }

            var item = itemArgs.ToItem(itemArgs.Item);
            if (item.SystemName != "MyItemType")
            {
                return;
            }

            // My code here
        }
    }
}
Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

ok, thank you Nuno 👍🏻

 

You must be logged in to post in the forum