Your Digital Media Has Never Looked So Good

 
Fenda
Topic Author
Posts: 5
Joined: Tue Jul 18, 2017 9:43 am

setFields() throws Type mismatch for strings

Thu Sep 07, 2017 3:48 am

I'm getting a Type mismatch error when using setFields() on a ContentNode that has an interface field type of string. Anyone else seeing this?


category = "foo"
show = createObject("RoSGNode", "ShowContentNode")
show.setFields({
  category: category
})
print Type(category) ' returns String
print Type(show.category) ' returns roString



Note that this is just a snippet but actually I am using setFields() because there are several fields I want to set at once. Here is the XML schema for ShowContentNode.

<?xml version="1.0" encoding="utf-8" ?>
<component name="ShowContentNode" extends="EntityContentNode">
  <interface>
    <field id="showTitle" type="string" />
    <field id="path" type="string" />
    <field id="category" type="string" />
    <field id="urlAlias" type="string" />
    <field id="hdposterurl" type="string" />
    <field id="sdposterurl" type="string" />
    <field id="heroPosterUrl" type="string" />
    <field id="tuneIn" type="string" />
    <field id="description" type="string" />
  </interface>
</component>


What's interesting is that I am able to set the field directly using the dot notation and I do not get the error. e.g:

show.category = category
 
joetesta
Posts: 513
Joined: Wed Apr 20, 2011 11:48 am

Re: setFields() throws Type mismatch for strings

Thu Sep 07, 2017 11:11 am

I'm working on something exactly like this at the moment and not seeing the error you describe.
In my case the app receives a response that is type "String" and calls a routine with this response passed in, the routine immediately sees the response type as "roString" however I have no trouble or type mismatch assigning to a field with type "string" using the "setfield" function;
Debug output:

 -------------------------------->>>> success response type String
 -------------------------------->>>> result response type roString

    content = CreateObject("roSGNode", "node")
    content.addField("result", "string", false)
    content.setField("result", result)


One thing I can suggest is that I saw odd buggy behavior in the past when using the word "show" as a variable, since "show" is also a command I think it should be a "reserved" word (to borrow perl lingo) try changing to something like "myshow" and see if that doesn't make a difference.  Alternatively perhaps the difference is you're using setfields vs addfield / setfield?
Hope it may help,
Joe
aspiring
 
Fenda
Topic Author
Posts: 5
Joined: Tue Jul 18, 2017 9:43 am

Re: setFields() throws Type mismatch for strings

Fri Sep 08, 2017 7:54 am

Thanks for the reply, Joe. Unfortunately, switching away from using the variable name show didn't help. I've also been able to resolve this by using setField (well, the dot notation equivalent shown in my original comment) but for performance reasons, we're supposed to use setFields(). Sounds like a bug to me.
 
User avatar
destruk
Posts: 2483
Joined: Sat Dec 18, 2010 4:58 pm

Re: setFields() throws Type mismatch for strings

Fri Sep 08, 2017 10:55 am

AddFields tries to add every existing value of your data source into the node, so it could be failing if you're adding a field not defined by default or specified by your interface field as an alteration of the standard component.  When using the 'dot' notation it ignores that stipulation and creates the missing field and then adds the value.

If you check here "category" isn't a valid default field in a content node.
https://sdkdocs.roku.com/display/sdkdoc ... +Meta-Data

It was renamed to "Categories" as a string --

Categories
String
Individual Category/Genre Name

Or you can use Categories as an roArray
Categories
roArray
List of Category/Genre Names

Sounds like a bug that it isn't working by adding it to the xml.
 
User avatar
destruk
Posts: 2483
Joined: Sat Dec 18, 2010 4:58 pm

Re: setFields() throws Type mismatch for strings

Fri Sep 08, 2017 11:08 am

Could you try this?
temp = "foo"
show=createObject("RoSGNode", "ShowContentNode")
show.setFields({
  category:temp
})
print Type(temp)
print Type(show.category)
 
Fenda
Topic Author
Posts: 5
Joined: Tue Jul 18, 2017 9:43 am

Re: setFields() throws Type mismatch for strings

Mon Sep 11, 2017 8:28 am

@destruk Thanks for the response, you put me on the right track.

These warnings seem to be a result of setting certain field names on a ContentNode. The names category and seasonNumber both seem to produce errors although they are not mentioned in the documentation as being possible fields. I changed the field names in both my XML structure that extends ContentNode and my setFields() code, and the errors went away. (e.g. field names are now showCategory and seasonNum).
 
User avatar
destruk
Posts: 2483
Joined: Sat Dec 18, 2010 4:58 pm

Re: setFields() throws Type mismatch for strings

Mon Sep 11, 2017 11:06 am

Excellent Fenda.  I wish there were more notes in the documentation about these issues.

Who is online

Users browsing this forum: No registered users and 2 guests