The following works just fine. I am “simulating” your field by creating two nullObject variables, one containing null and the other containing a string.
var myMeta = new ActiveXObject("Metadatalib.metafile");
myMeta.LoadFromFile(Watch.GetMetadataFileName());
var nullObject1=null;
var nullObject2="Goodbye";
var myGroup = myMeta.Job().Group(0);
myGroup.Fields.Add2("Hello", (nullObject1 || "world"),2)
myGroup.Fields.Add2("Hello", (nullObject2 || "should not be used"),2)
myMeta.SaveToFile(Watch.GetMetadataFileName());
The code inserts fields in the first document of the metadata. When you inspect the results, you’ll see the values are inserted exactly as expected.
When does it spawn a type conflict? When it’s null, when it’s not null, both?
In any event, at this stage you may want to use the coalesce SQL method to ensure you don’t have to go through these hoops. Better yet, configure your database to insert an empty string in empty fields (rather than a null value). I am no database expert but I know most if not all DB Engines allow you to do that.
Phil, yes, I already changed the select statement (using coalesce or isnull) so everything works, but I don’t want to give attention to every incoming field, esp. 'cause data comes from our customers. I’ll give vbscript a try, maybe it’s about the jscript. the “OR” method stated above should work (as mentioned in several blogs) but there seems to be something wrong with Planet Press implementation.
As I’ve demonstrated before, the OR method works. It’s the null content of your field that apparently cannot be converted to something JScript understands.
Our implementation of JScript is that of Microsoft’s Windows Scripting Host, so it’s not something proprietary.
since I’m using the ActiveX ADODB component the issue might be there, backend SQL is MSSQL 2014. I’ll try another dataprovider.
Best way to get data out of MSSQL is the ADODB connection with provider sqloledb, that’s what I actually use. So who to blame? Open support ticket?
seems that there’s no way to do it in jscript. I recoded the db-lookup in vbscript, so the assignment (with a dirty trick to overcome the null values by adding & “”) now is: