Sidebar

How can I format source node to HHmm into message node

0 votes
309 views
asked May 20, 2021 by dana-h-4328 (190 points)
I have a source node with "730" and I want to pass that to the message as HHmm.  (Or, at least I need to make sure the data always gets passed thru as 4 digits.)  When I do, I get no value at all.  Code I used:

var value = source.getNode("10");
value = qie.formatDate("HHmm", value);
message.setNode("SCH-11.3", value);

I am sure my ignorance is showing!  Thank you.

1 Answer

0 votes
 
Best answer
You could left pad with zeros.

replace

value = qie.formatDate("HHmm", value);

with

value = StringUtils.leftPad(value, 4, '0');
answered May 20, 2021 by michael-h-5027 (14,350 points)
selected May 20, 2021 by dana-h-4328
commented May 20, 2021 by dana-h-4328 (190 points)
Oh shoot....The source node may have 3 or 4-digit times, so padding won't work. I forgot this part on first ask!
commented May 20, 2021 by michael-h-5027 (14,350 points)
leftpad will handle 3 or 4 characters. 730 would be 0730 and 1154 would be 1154 with no change.
commented May 20, 2021 by dana-h-4328 (190 points)
Thank you!  I can now go live.
...