Combo Box resetting to special list value fails with Specified cast is not valid

i have a simple combo box on a list screen. The value selected is used in a search.
Source Entity and Source Attribute are set for the Combo Box.
i have a special list value 1 set to 0
this is used when the user doesn't want to select anything from the combo box

the selected value is stored in a session variable of type Entity Identifier.

when the reset button is clicked i set the session variable to a null identifier  but i keep getting Specified Cast is not valid when the Combo Box is displayed on the screen . 

i can select the special list value manually and then the session variable is set to a null identifier i.e. 0

i have also tried to set the SpecialListValue to "0" but that didn't help either.
any ideas would be greatly appreciated

thank you
Hi Fabian,

Please share sample oml of issue you are facing.

It's difficult to tell what's going on without seeing your code, so like Suraj aid, it'll help if you post an OML that exhibits this problem.

Combo boxes with both a Source Record List or Source Entity and a Special List must have the Variable property set to a variable that's the same type as the Source Identifier Attribute, or in case of a Source Entity, as the Id of the Entity. When you select an item from the Source Record List/Source Entity, the Variable will contain the value of the Id. When you select an item from the Special List, the Variable will contain a value of NullIdentifier(). If you set the Special Variable, it will contain the Value of the selected entry from the Special List, or the empty value (0 for numeric, empty string for string types, False for Boolean).

If neither the Variable nor the Special Variable are set, the platform will pick the first entry of the Special List.
thank you very much for your help.

attached is a sample app. chopped out a lot so it's not really doing much but you can see the issue i'm having.
after you publish it enter a few vote source file names. then go to the votes screen and select a a meeting type aka vote source search...nothing will show up but that's ok...then click you should see the specified cast is not valid error
Hi Fabian,

It took me some time to find out what's wrong, and the good news is, it's not your fault! :) The bad news, of course, is that this is a platform bug. I've encountered something similar it myself some time ago, but this had to do with decimals instead of Ids, so I didn't immediately make the connection.

To find the cause, I had to manually alter the C# code the platform produces and add some Audits. The problem is that Session Variables are stored in an associative array of variable type. When the screen starts, it's type is (correctly) System.Int64, as your identifier is a Long Integer. However, when you assign NullIdentifier to it, the platform assigns BuiltInFunction.NullIdentifier() to the session variable, but that seems to return a System.Int32, in effect changing the type of the session variable to System.Int32. When you do the Ajax refresh, the platform calls a function called selcbxSourceFileNames_onDataBinding (you can see that name appearing in the Service Center error log stack trace), which tries to cast the session variable to a long, which is invalid, and you get the cast error.

So, what to do? As a workaround, you could use a local variable instead of a session variable for the combo box, and instead of assigning NullIdentifier() to the session variable, assign it to the local variable, then assign the local variable to the session variable (and don't forget to initialize the local variable in the preparation by assigning the session variable to it). Or, you could (depending on the stage of development you're in) change the identifier of the table from long int to int, since it doesn't seem you'll have billions of records in that table anyway (note that in order to do this, you need to Ctrl-X/Ctrl-V the table, and you'll lose all the data currently stored in it, as you cannot convert from int to long int, at least not in MSSQL).

I'll report this issue to OutSystems Support, so they can fix it forthwith. Hopefully they'll fix it soon.
wow thank you so much for figuring this out. amazing detective work. I will change the id from long integer to integer. this is actually great to know since very often an integer is bug enough Thank you for submitting this to outsystems. Have a nice day.
Hey Fabian,

The issue was already fixed and you will find it in one of the next patches. Check the Change Log and search for the issue #1207410.

Thank you for your feedback!


For those still having issues with this (in older versions of the platform), I've setup an example online so you can test and inspect the code - please download it from the demo, as well.

...I'm getting a weird error in the download. Please get it from the attach in this post.