Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mkdir1995
Visitor

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!
Tags (1)
0 Kudos
6 REPLIES 6
tim_beynart
Channel Surfer

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
Channel Surfer

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
RokuNB
Roku Guru

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})
mkdir1995
Visitor

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
Channel Surfer

Re: How to add custom field to Node?

well damn, that is much easier
0 Kudos
norcaljohnny
Roku Guru

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 🙂
0 Kudos