How to update a particular value in a Multiple Value Constant ?

Dear Team,

I have multiple text value constant (e.g. cons!Country) where i have 4 values (e.g. India, America, China, Italy), similarly i have the same details in a Database Table. when ever an update is happening in the database table on the Country name, then the same changes should be updated in the constant as well. But the order of the list in constant can't be changed, because it is hard coded in many interface for some validation using the Constant value Index.

I know how to find a particular value in a Constant(Multiple Text Value), but not sure how to update a particular value in a constant.

Please help me with some suggestions for this problem.

  Discussion posts and replies are publicly visible

Parents
  • My initial thoughts are that you may well be past the point where I would recommend that you NOT use a constant as an array of values, as you are now hitting the very issues I would highlight if I were reviewing the code. Use of constants as arrays has two main issues:

    1. they are fragile when subject to change that is, the order of their elements can become incredibly important and can break your implementation if the order changes
    2. it makes implementations hard to read and therefore slower to maintain and support - for example, you may have code that compares a variable to cons!Country[3] when you are referencing 'China' (according to your example). without navigating to the constant to see what the third instance or without explicitly documenting the code the implementation cannot be natively read and understood

    A better implementation would be for each element to be its own single-value constant: cons!COUNTRY_INDIA, cons!COUNTRY_AMERICA etc.

    Then where you need a list you simply write an expression:

    {
    cons!COUNTRY_INDIA,
    cons!COUNTRY_AMERICA,
    ...etc
    }

    As I said, this may well be too late for your application, but it's worth bearing in mind for future implementations.

    Having said all that, if you need to solve the problem to hand you'll have to effectively update the entire contents of the constant. You can extract the value to a process variable so that it now exists as a list of text, then you can update the element in that list and then write the entire list back to the constant. It's not pretty, and another good reason not to implement the constant-as-an-array pattern.

  • I'm also curious - if you already have the data in a database table, why do you also have a constant? The database is easier to update while still being easy to query anywhere you need the value. Plus, you can perform filtering on the data in the database and include multiple rows.

    Like Stewart said, if you have already implemented your solution with a constant, it may not be worth going back to change it. However, if you aren't too far along, it will be a lot easier to use the database table directly instead of a constant.

Reply
  • I'm also curious - if you already have the data in a database table, why do you also have a constant? The database is easier to update while still being easy to query anywhere you need the value. Plus, you can perform filtering on the data in the database and include multiple rows.

    Like Stewart said, if you have already implemented your solution with a constant, it may not be worth going back to change it. However, if you aren't too far along, it will be a lot easier to use the database table directly instead of a constant.

Children
No Data