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.

  • For time being we can't touch the constant , as it is used in multiple interface validations.

    I have used Update constant smart service to achieve it, but facing one issue with it. Would be great if you can help with the issue am facing. In a process model there is a User Lane and System Lane, in the System Lane the update constant smart service is placed. When i run the process model for the first time then the update is happening in the Constant, when i try to re-update in the same session, then the Update Constant smart service is showing an exception "The user does not have sufficient privileges to update the constant. Constant ID"

    When i use a Tech Admin ID then it is working though i update multiple times, if i use a User from the User Group then the privileges issues raised, but that even when i re-update the constant and not in the first time.

Reply
  • For time being we can't touch the constant , as it is used in multiple interface validations.

    I have used Update constant smart service to achieve it, but facing one issue with it. Would be great if you can help with the issue am facing. In a process model there is a User Lane and System Lane, in the System Lane the update constant smart service is placed. When i run the process model for the first time then the update is happening in the Constant, when i try to re-update in the same session, then the Update Constant smart service is showing an exception "The user does not have sufficient privileges to update the constant. Constant ID"

    When i use a Tech Admin ID then it is working though i update multiple times, if i use a User from the User Group then the privileges issues raised, but that even when i re-update the constant and not in the first time.

Children