Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
mkdir1995
Level 7

How to add custom field to Node?

I can't seem to find anything on the forum or in the SDK on how to add a custom field into the node object. For example, a roSGNode is set up like this:
 
<Component: roSGNode> =
{
    change: <Component: roAssociativeArray>
    focusable: false
    focusedChild: <Component: roInvalid>
    id: ""
    DESCRIPTION: ""
    HDBACKGROUNDIMAGEURL: ""
    HDPOSTERURL: ""
    RELEASEDATE: ""
    STREAMFORMAT: ""
    TITLE: "cartoon 1"
    URL: ""
}



Now, using my server data, I know I can program my content with the corresponding Content Meta Data. I can set the TITLE, URL, DESCRIPTION, id etc because that is what is provided to me in the roSGNode. What if I need custom fields in order to continue setting up my application? For example, I need to add a TYPE right under the 'URL' in the node above.
I tried using .addFields() but that didn't seem to work.

Any help is greatly appreciated since I've been trying for a few days and can't figure it out. Thanks!
0 Kudos
6 Replies
tim_beynart
Level 7

Re: How to add custom field to Node?

you extend the node, then you can add any fields you want.
For example:
<?xml version="1.0" encoding="utf-8" ?>
<component name="media_item" extends="ContentNode">
<interface>
<field id="thumbnail" type="string" />
<field id="content_type" type="string" />
<field id="title" type="string" />
<field id="entitlement" type="string" />
<field id="guid" type="string" />
<field id="duration" type="float" />
<field id="category" type="string" />
<field id="ratings" type="array" />
<field id="genres" type="array" />
<field id="daypart" type="string" />
<field id="program" type="string" />
<field id="episode" type="string" />
<field id="season" type="string" />
<field id="airdate" type="string" />
<field id="callsign" type="string" />
</interface>
</component>
0 Kudos
tim_beynart
Level 7

Re: How to add custom field to Node?

it's covered, briefly, in step 6 of this lesson:
https://github.com/learnroku/crash-cour ... Lesson3.md
0 Kudos
Roku Employee
Roku Employee

Re: How to add custom field to Node?

Or you can add fields dynamically, without extending-through-XML/compilation - as simple as:
myNode.addFields({myNewField: value1, more2: 7})
0 Kudos
mkdir1995
Level 7

Re: How to add custom field to Node?

I ended up using addFields, it does exactly what I need to do without the extra XML confusion. Works like a charm. Thanks all!
0 Kudos
tim_beynart
Level 7

Re: How to add custom field to Node?

well damn, that is much easier
0 Kudos
norcaljohnny
Level 7

Re: How to add custom field to Node?

"tim_beynart" wrote:
it's covered, briefly, in step 6 of this lesson:
https://github.com/learnroku/crash-cour ... Lesson3.md

Hey Tim, I read that course and it was a goodie. You provide a lot of good information that is clear and to the point.
Cheers Smiley Happy
0 Kudos