Sidebar
0 votes
421 views
by daniel-d-7319 (270 points)
edited by brandon-w-8204
I am trying to increment an value stored in channel cache and it is appending not adding.

1 Answer

+1 vote

channelCache.getValue returns a Java String.

What this means is the following line will append:

var msg_Control_ID = channelCache.getValue('channelCacheKey');
msg_Control_ID = msg_Control_ID+1;

if channelCacheKey is value 1 the result in msg_Control_ID would be 11 not 2 as you are expecting.

To correct this you need to convert the value from the Channel Cache to an integer vs a string:

var msg_Control_ID = channelCache.getValue('channelCacheKey');
// convert msg_Control_ID to a number or integer
msg_Control_ID  = msg_Control_ID*1;
// increment the number by one.
msg_Control_ID = msg_Control_ID+1;

 

by brandon-w-8204 (34.1k points)
...