Hello,
I have a form with a grid and I need to color 2 columns of the grid depending on the values of the other 2 different columns.
Do you happen to bump into something similar?
Hello,
I have a form with a grid and I need to color 2 columns of the grid depending on the values of the other 2 different columns.
Do you happen to bump into something similar?
If this isn't what you want, you've chosen a wrong solution for your business problem.
I don't know your business requirement, therefore I can't propose a better design. But there surely are other approaches, such showing icons (through display methods) instead of changing background colors, showing colors in details instead of a grid, or using a report instead of a form.
Yes, it is not exactly what I need since the usual case is that the record met one of the conditionals in each switch.
The first call of affectedElementsByControl() has no effect, because you always overwrite the value by the second affectedElementsByControl() call.
You will need to set the control only when the condition is met:
public void displayOption(Common _record, FormRowDisplayOption _options) { MyTable table = _record; switch(table.MyField_1) { case value_1: _options.backColor(WinAPI::RGB2int(#PastelRed)); _options.affectedElementsByControl(MyControl_1.id()); break; case value_2: _options.backColor(WinAPI::RGB2int(#PastelYellow)); _options.affectedElementsByControl(MyControl_1.id()); break; } switch(table.MyField_2) { case value_3: _options.backColor(WinAPI::RGB2int(#PastelRed)); _options.affectedElementsByControl(MyControl_2.id()); break; case value_4: _options.backColor(WinAPI::RGB2int(#PastelYellow)); _options.affectedElementsByControl(MyControl_2.id()); break; } super(_record, _options); }
I'll improve the situation, but your expectation isn't correct anyway - the controls won't be completely independent. You aren't setting a colour for a column - you're setting a colour for a record (and choosing which controls it'll apply to). If conditions for both fields are met, colour will be set according to MyField_2, because it'll overwrite backColor set by MyField_1.
public void displayOption(Common _record, FormRowDisplayOption _options) { MyTable table; table = _record; _options.affectedElementsByControl(MyControl_1.id()); switch(table.MyField_1) { case value_1: _options.backColor(WinAPI::RGB2int(#PastelRed)); break; case value_2: _options.backColor(WinAPI::RGB2int(#PastelYellow)); break; } //_options.clear(); _options.affectedElementsByControl(MyControl_2.id()); switch(table.MyField_2) { case value_3: _options.backColor(WinAPI::RGB2int(#PastelRed)); break; case value_4: _options.backColor(WinAPI::RGB2int(#PastelYellow)); break; } super(_record, _options); }
What is expected: MyControl_1, MyControl_2 colors are independent and are determined by MyField_1 and MyField_2 relatively.
What happened: the second switch rewrites the first switch and as a result both controls colors are based on MyField_2.
It seems that you have code that doesn't work as expect. Please share it with us. (Use Insert > Code in the rich formatting view to paste source code).
By the way, you didn't respond to my questions about forums. Your previous question was in a D365FO forum and this one is in the AX forum. Doesn't it actually belong to a D365FO forum too?
Yes, it is the same task but a bit different problem. I solved the previous one as you recommended. But now I encountered that whenever I try to color the first column and then the second one then both columns have colors based on the second column logic.
Isn't it about the same thing as your thread Color the grid column depending on other column? If so, let me delete this one. It's better to have the discussion at one place.
Did you see my response there?
Also, the other thread is in Dynamics 365 Finance forum - doesn't this thread belong there too? (Assuming that it's not a duplicate.)
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156