I am trying to check to see if a node is blank, and if it isnt, then append additional information to it. This portion I can do. What I am wanting to do is a if /else and have it adjust another node if the node being check is blank.
I have tried the following and it tells me that the value is already defined.
if (source.checkNodeExists('PID-14.1')) {
var value = source.getNode("PID-14.1");
message.setNode("PID-14.1","^PT^" + value);
} else {
var value = source.getNode("PID-13.1");
message.setNode("PID-13.1","^PT^" + value);
}
What can I do to make this work?
You're getting that error because "value" is being declared twice in your if statement. Try:
var value = '';
if (source.checkNodeExists('PID-14.1')) {
value = source.getNode("PID-14.1");
message.setNode("PID-14.1","^PT^" + value);
} else {
value = source.getNode("PID-13.1");
message.setNode("PID-13.1","^PT^" + value);
}
Didn't work. It just put the ^PT^ in node 14 instead of in node 13.
Ah ha, I got it. Needed to check if the node is blank instead of if it existed cause it does, every time.
This code worked.
var value = '';
if (message.checkNodeIsNotBlank('PID-14.1')) {
value = source.getNode("PID-14.1");
message.setNode("PID-14.1","^PT^" + value);
} else {
value = source.getNode("PID-13.1");
message.setNode("PID-13.1","^PT^" + value);
}