C# Variable not updating properly?

We have a screen customization with a button that calls an internal URL. I want to set a few query string parameters on the URL based on the company / plant combination.

However I have a problem with my C# trying to set the parameters. They never get changed after I set them. I think it’s a variable scoping thing. I’m a C# noob.

Are you sure its entering any of the if statements? Have you tried putting a message box inside to be sure?

Also, careful with string comparisons, its more complicated than you might think: https://docs.microsoft.com/en-us/dotnet/csharp/how-to/compare-strings

I figured out why it wasn’t working. The company and plant weren’t getting set until the second time I clicked the button so it was a timing issue. I moved some initialization of company and plant to the custom code initialization section of the customization and now the code is behaving as expected.

Popping open message boxes helped.

For anyone in the future. Here’s how I opened a message box inside a screen customization:

EpiMessageBox.Show("Message here");

Yep, message boxes can be quite helpful for debugging, you can display variables too.