Sidebar

Checking to see if a node is blank and then using a different one if it is

0 votes
400 views
asked Jan 14, 2019 by earnest-t-7587 (150 points)
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?

1 Answer

+2 votes
 
Best answer
There are 2 issues, the code is checking to see if the node exists, not to see if it is blank.  The 'alreay defined' error is because you are declaring the same variable of 'value'  a second time.  The code below addresses both of these issues by checking the node is blank and just re-using the variable 'value' without declaring it a second time.

 

if (source.checkNodeIsBlank('PID-14.1'))   {
   var 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);
}
answered Jan 14, 2019 by terrie-g-7436 (3,950 points)
selected Jan 14, 2019 by earnest-t-7587
commented Jan 14, 2019 by earnest-t-7587 (150 points)
Thanks.  That worked.
...