Script to update values for specific items

237 viewsScripting

Hi Everyone,

I’m trying to update the values on specific items using a script and haven’t found the right combination to use. In the screenshot I want the outcome of the script to input a 1 in Filter anytime the dept item contains “Total Dept”.

Thanks for looking!

if (|matrix2|.getSelection(it, |matrix2::dept|).value.contains("Total Dept"))
it.value = 1()

Gilbert Answered question June 24, 2024

Hi jeffc,

I agree with S A U that IF formula does the trick, it should be preferred (as there are no script triggers available, therefore the user must not forget to run the Update-script).

If your concern is that the automatic value has to be manually overwritten, there is a “standard” solution for it: Create a “Layer” category which contains different layers for this value, e.g. “Input” for manual input, “Formula” for the automatic value, and “Final” which then chooses on certain criteria which on to take, e.g. “if input is given take input, if input is empty take formula”. This works very well and clean for all sorts of inputs. Also to protect input if the user has not right to change (see Dimensions 2023 session from Ben), or to provide default values which are used if there is not input.

Usually, you will only present the “input” layer to the user, but I have shown all layers side by side for clarity.

Hope this helps as an idea. Maybe script will be better for you, but maybe this kind of input layers will solve the problem nicer.

Good luck, Gilbert




S A U Posted new comment June 25, 2024

Gilbert, FYI: a problem of manually overriding calculated values was solved already in 2017 rather than 2023.
See model file: ‘How to manually override calculated values.model’


Hi jeffc,

A value in the script above refers to the value of an item in the cell. Here you should use name of an item because, as I see from your matrix, you would like to refer to the item’s name, and check if it contains specific text. Please see below the script you are looking for.


myItems = |Matrix55::dept|.items

int categorySize = |Matrix55::dept|.items.size()

for (j=0;j<categorySize;j++)  {

if (myItems[j].name.contains("Total dept"))

myItems[j].value = 1
jeffc Posted new comment June 25, 2024

Thank you Tahir this worked!


If this is applicable, use a formula solution instead of a script

Good luck

jeffc Posted new comment June 21, 2024

Hi S A U,

No, I need the field to be editable which is why I can’t have it solved in a formula. thank you for looking!