How to convert array into single value against a single key

Certified Lead Developer

I've CDT which has data like {ID:1, Val: "A,B,C}. Now I want to store the values in another CDT and write to DB where I want to save them in manner like {ID:1, Val:"A", ID:1, Val:"B",ID:1, Val:"C"}. What can be done to achieve this.

Regards:
Nitesh

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    You can't have multiple properties with the same name (i.e. "Val") in a CDT, nor can you really have a variable number of properties (though there's nothing keeping you from adding the maximum number that you'll ever likely need).  They would need unique names, like {val1, val2, val3} etc.

    If the list of "Val" is going to be completely variable then you might want to consider making an association table where you add a new row for each one, where each row has a reference to the "ID", and a reference to the "Val" value.  This table would also need its own primary key, separate from the original "ID".

    But at this point your use case is not clear enough and it's getting to be too much guesswork to say anything specific about it without potentially going in the wrong direction.  Is there any more detail you can provide as to the nature of your input data and what you need it transformed into?  Would "A,B,C" be literally a comma-separated single text value, or would it be an array, for example?  How long would it get?  These are just a few points of clarification needed to really be helpful for you.

Reply
  • 0
    Certified Lead Developer

    You can't have multiple properties with the same name (i.e. "Val") in a CDT, nor can you really have a variable number of properties (though there's nothing keeping you from adding the maximum number that you'll ever likely need).  They would need unique names, like {val1, val2, val3} etc.

    If the list of "Val" is going to be completely variable then you might want to consider making an association table where you add a new row for each one, where each row has a reference to the "ID", and a reference to the "Val" value.  This table would also need its own primary key, separate from the original "ID".

    But at this point your use case is not clear enough and it's getting to be too much guesswork to say anything specific about it without potentially going in the wrong direction.  Is there any more detail you can provide as to the nature of your input data and what you need it transformed into?  Would "A,B,C" be literally a comma-separated single text value, or would it be an array, for example?  How long would it get?  These are just a few points of clarification needed to really be helpful for you.

Children
No Data