# Template for note containing variable length string

**URL:** <https://discuss.blues.com/t/template-for-note-containing-variable-length-string/1541>\
**Category:** Uncategorized\
**Created:** [August 4, 2023, 10:58am UTC](https://discuss.blues.com/t/template-for-note-containing-variable-length-string/1541 "2023-08-04T10:58:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlkeith](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/rlkeith/32/886_2.png) [@rlkeith](https://discuss.blues.com/u/rlkeith)\
**Post date:** [August 4, 2023, 10:58am UTC](https://discuss.blues.com/t/template-for-note-containing-variable-length-string/1541/1 "2023-08-04T10:58:01Z")

</div>

Hi All,

This might be really simple, but I am having trouble getting it. I am trying to create a template for a message that will contain a variable length string. The string is usually 2062 characters long, so if I do this:

JAddStringToObject(body, “log\_data”, “2062”);

does it mean I am allocating a fixed length string, or is the string variable length?

The string will be either empty or “none”, 150 bytes or 2062 bytes. Maybe I could create three templates with different data lengths.

Thanks in advance,

Rob

---

<div class="post-metadata">

**Author:** ![rlkeith](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/rlkeith/32/886_2.png) [@rlkeith](https://discuss.blues.com/u/rlkeith)\
**Post date:** [August 4, 2023, 11:16am UTC](https://discuss.blues.com/t/template-for-note-containing-variable-length-string/1541/2 "2023-08-04T11:16:22Z")

</div>

Perhaps I am getting ahead here, but how about I do this:

Set up three templates with three different data files: logdata.qo, devstatus.qo and commfail.qo, with structures appropriate to each type of message.

Set up three routes, each one to handle the different files and to send the messages to three different API controllers.

Can anyone see a problem with this?

Thanks,

Rob

---

<div class="post-metadata">

**Author:** ![drrk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/drrk/32/836_2.png) [@drrk](https://discuss.blues.com/u/drrk)\
**Post date:** [August 4, 2023, 11:23am UTC](https://discuss.blues.com/t/template-for-note-containing-variable-length-string/1541/3 "2023-08-04T11:23:24Z")

</div>

Hi Rob,

This is different on versions prior to v3.2.1 and after. In the older versions, the length is the max length a string can be, but a string of any length up to that can be used. In the later versions, the string is variable length. I am however not sure of the specifics of this, as the documentation is unclear, I will follow up.

[Low Bandwidth Design - Blues Developers](https://dev.blues.io/notecard/notecard-walkthrough/low-bandwidth-design/#understanding-template-data-types) is the documentation I was referring to.

Kimball

---

<div class="post-metadata">

**Author:** ![RobLauer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/roblauer/32/1567_2.png) [@RobLauer](https://discuss.blues.com/u/RobLauer)\
**Post date:** [August 4, 2023, 1:31pm UTC](https://discuss.blues.com/t/template-for-note-containing-variable-length-string/1541/4 "2023-08-04T13:31:59Z")

</div>

@rlkeith,

Just to clarify - when you are establishing a template (which only needs to be done once), the value you pass to configure a given parameter as a string can be **any arbitrary string value**. Like Kimball stated, as long as you are on Notecard firmware \>= 3.2.1, you don’t have to specify a `length` argument either, and thus strings can be of any length:

```auto
JAddStringToObject(body, "log_data", "x");

```

When using this template, your `log_data` string can be any length.

If you need to route three different sets of data, having three different Notefile names (and thus three different templates) is probably the right way to go.

Rob

---

<div class="post-metadata">

**Author:** ![rlkeith](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/rlkeith/32/886_2.png) [@rlkeith](https://discuss.blues.com/u/rlkeith)\
**Post date:** [August 4, 2023, 1:39pm UTC](https://discuss.blues.com/t/template-for-note-containing-variable-length-string/1541/5 "2023-08-04T13:39:48Z")

</div>

Thanks again. I am using 3.5.2.15620, which seems to be the default.

I have got it sending the messages very happily; queueing up 10 messages and syncing. I will keep refining it.

Rob
