Fenda
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017
03:48 AM
setFields() throws Type mismatch for strings
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?
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.
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:
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
6 REPLIES 6
joetesta
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017
11:11 AM
Re: setFields() throws Type mismatch for strings
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:
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
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
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017
07:54 AM
Re: setFields() throws Type mismatch for strings
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.
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017
10:55 AM
Re: setFields() throws Type mismatch for strings
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.
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.
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017
11:08 AM
Re: setFields() throws Type mismatch for strings
Could you try this?
temp = "foo"
show=createObject("RoSGNode", "ShowContentNode")
show.setFields({
category:temp
})
print Type(temp)
print Type(show.category)
temp = "foo"
show=createObject("RoSGNode", "ShowContentNode")
show.setFields({
category:temp
})
print Type(temp)
print Type(show.category)
Fenda
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017
08:28 AM
Re: setFields() throws Type mismatch for strings
@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).
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).
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017
11:06 AM
Re: setFields() throws Type mismatch for strings
Excellent Fenda. I wish there were more notes in the documentation about these issues.