Global varibles in a payload

Just trying to send a payload to a zebra printer and Im having a bad day!

msg.payload = '^XA ^CFA,30 ^FO50,300^FDTicket Number: "+global.get(Ticket)+"^FS ^FO50,330^FDRego:"+rego+"^FS ^FO50,360^FDColour: "+color+"^FS ^FO50,390^FDMake: "+make+"^FS ^FO50,420^FDModel: "+model+"^FS ^FO50,450^FDDate/Time: "+datetime+"^FS ^FO50,480^FDJob Origin: "+originsub+"^FS ^FO50,510^FDTime Printed: "+timeprinted+"^FS ^FO50,540^FDNotes: "+global.get(notes)+"^FS  ^CFA,32   ^FX Third section with bar code. ^BY5,2,270 ^FO100,590^BC^FD12345678^FS  ^FO50,950^FDRelease Date: "+global.get(release)+"^FS   ^XZ'
return msg;

Debug window

25/05/2023, 18:23:37node: debug 6
msg.payload : string[500]
"^XA ^CFA,30 ^FO50,300^FDTicket Number: "+global.get(Ticket)+"^FS ^FO50,330^FDRego:"+rego+"^FS ^FO50,360^FDColour: "+color+"^FS ^FO50,390^FDMake: "+make+"^FS ^FO50,420^FDModel: "+model+"^FS ^FO50,450^FDDate/Time: "+datetime+"^FS ^FO50,480^FDJob Origin: "+originsub+"^FS ^FO50,510^FDTime Printed: "+timeprinted+"^FS ^FO50,540^FDNotes: "+global.get(notes)+"^FS  ^CFA,32   ^FX Third section with bar code. ^BY5,2,270 ^FO100,590^BC^FD12345678^FS  ^FO50,950^FDRelease Date: "+global.get(release)+"^FS   ^XZ"

The variables arent working :frowning:

Can somebody enlighten me where I am going wrong?

Thanks

I'm not sure, but I think there is some disparity with the " and ` and ' used.

Maybe try to test things with a more simple example.

And not send it to the printer, just a debug node.

eg:
msg.payload = 'this is some text' + global.get("something")

Of course you will have to have global.something set to .... something.
See what you get in the debug node.

You start with single quotes then use double quotes, you need to use one or the other

msg.payload = "^XA ^CFA,30 ^FO50,300^FDTicket Number: "+global.get(Ticket)+"^FS ^FO50,330^FDRego:"+rego+"^FS ^FO50,360^FDColour: "+color+"^FS ^FO50,390^FDMake: "+make+"^FS ^FO50,420^FDModel: "+model+"^FS ^FO50,450^FDDate/Time: "+datetime+"^FS ^FO50,480^FDJob Origin: "+originsub+"^FS ^FO50,510^FDTime Printed: "+timeprinted+"^FS ^FO50,540^FDNotes: "+global.get(notes)+"^FS  ^CFA,32   ^FX Third section with bar code. ^BY5,2,270 ^FO100,590^BC^FD12345678^FS  ^FO50,950^FDRelease Date: "+global.get(release)+"^FS   ^XZ"
return msg;

Or use template string

msg.payload = `^XA ^CFA,30 ^FO50,300^FDTicket Number: ${global.get(Ticket)}^FS ^FO50,330^FDRego:${rego}^FS ^FO50,360^FDColour: ${color}^FS ^FO50,390^FDMake: ${make}^FS ^FO50,420^FDModel: ${model}^FS ^FO50,450^FDDate/Time: ${datetime}^FS ^FO50,480^FDJob Origin: ${originsub}^FS ^FO50,510^FDTime Printed: ${timeprinted}^FS ^FO50,540^FDNotes: ${global.get(notes)}^FS  ^CFA,32   ^FX Third section with bar code. ^BY5,2,270 ^FO100,590^BC^FD12345678^FS  ^FO50,950^FDRelease Date: ${global.get(release)}^FS   ^XZ`
return msg;

Also are release, notes and ticket etc variables? if not they also need to be in quotes, single quotes in first example, template string you can use either.

"^XA ^CFA,30 ^FO50,300^FDTicket Number: 36689686^FS ^FO50,330^FDRego: Tam796 ^FS ^FO50,360^FDColour:Blue^FS ^FO50,390^FDMake:Holden^FS ^FO50,420^FDModel:Caprice^FS ^FO50,450^FDDate/Time:undefined^FS ^FO50,480^FDJob Origin: RAC DOIT Driver Own Insurance Tow ^FS ^FO50,510^FDTime Printed: undefined^FS ^FO50,540^FDNotes: Notes -^FS  ^CFA,32   ^FX Third section with bar code. ^BY5,2,270 ^FO100,590^BC^FD12345678^FS  ^FO50,950^FDRelease Date:undefined^FS   ^XZ"

Sorted.. Thanks Gents :slight_smile:

Mark the reply which best solved it to help others. :wink:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.