How can I read in two fields together in the Editor form, but split them when I store in the table?

How can I read in two fields together in the Editor form, but split them when I store in the table?

pharrispharris Posts: 7Questions: 2Answers: 0

We have a barge system that contains owner IDs and barge numbers that are always paired together.

Ex: Owner ID: CBC and Barge Number: 123 make a pair of CBC 123.

I have an api that will return the Owner ID + Barge Number for a select2, but I would like to store the two fields separately in my database. I'm working with the .NET libraries.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    It sounds like an idea use case for a left join. The pair would be stored in a table (possibly with the Owner ID being the primary key, or perhaps a new sequential key) and the select2 input would select the appropriate primary key.

    Or do you need the two values to be set in the host table and Select2 will submit some kind of formatted string that can be deformatted into the two values? If so, then you could use a set formatter to do that.

    Allan

  • pharrispharris Posts: 7Questions: 2Answers: 0

    Allan,

    The second scenario is what I'm going for. I know I can return the full string "CBC 123" from my select, but I'm not sure how to tell the backend via the set formatter to split and store them in the respective columns. i.e. CBC into OWNER_ID and 123 into BARGE_NUM

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    You would use a set formatter on each of the two fields with a custom function. They could be as simple as splitting the string value by a space and then return the first or second element in the resulting array.

    Allan

This discussion has been closed.