# Substring error

**URL:** <https://discourse.nodered.org/t/substring-error/6192>\
**Category:** Dashboard\
**Created:** [28 December 2018 11:37 UTC](https://discourse.nodered.org/t/substring-error/6192 "2018-12-28T11:37:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![salvodj](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@salvodj](https://discourse.nodered.org/u/salvodj)\
**Post date:** [28 December 2018 11:37 UTC](https://discourse.nodered.org/t/substring-error/6192/1 "2018-12-28T11:37:18Z")

</div>

good morning, sorry for my english. I have a problem with a debug error. It always appears to me

"TypeError: Cannot read property 'substring' of undefined"

the function I have

var codice = msg.payload.rfin;  
msg.payload = codice;  
msg.payload = msg.payload.substring(12,msg.payload.length - 0);

if (msg.payload === "F5582B") {  
var test = true ;  
msg.payload = test;  
return msg;  
}else {  
return [null, msg];  
}

I thank you for help

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 December 2018 12:00 UTC](https://discourse.nodered.org/t/substring-error/6192/2 "2018-12-28T12:00:04Z")

</div>

The error is saying that at that point msg.payload has the value undefined, which means that codice is undefined so msg.payload.rfin was undefined.  
Feed the message you are passing to the function into a debug node and see what it says.
