Global.get is losing select array data

I have a global context, that when I retrieve it with global.get, loses three integers from an array of 14 entries.

I have created a global context over a number of nodes that stores a data for a process. The data is entered over about a dozen steps. The data in questions is three objects and two arrays deep. The bottom array represents information about a document. The parent array is a collection of all documents in the group.

In one node I pull down the global context just like I do with all previous nodes but when I extract all the entries in an array I find that the first two entries are fine but all subsequent entries have lost the data for array element 9, 10 and 11. All other entries are fine. When I pull the context outside of the function node it is fine. What am I missing?

The elements in question are all created in one previous function node but there dosent seem to be an issue there as the data is entered correctly.

Does anyone have any ideas? The code of the node in question is below.

//2. Create Variables:
//a. nmsg for new outgoing msg
var nmsg = {}

//b. validation_messages for global calc_checksum variable
var validation_messages

//c. my_time to store a timestamp
var my_time

//d. task_guid for the guid of the current task
var task_guid

//e. temp variables for random short term tracking
//Create temp vars 
var  test
var counter = 0
var temp0 = []
var temp1
var temp2
var temp3
var temp4
var regexp

//Create timestamp
my_time = Date.now()

//3. Get globbal calc_checksum variable
validation_messages = global.get("calc_checksum");

//Check if it exists, if it doesn't then return nothing
if (validation_messages == null) {
	return;
}

//Update Global Task_submit timestamp
validation_messages.timestamp = my_time

//Iterate through all objects in global task_submit  
for (var key in validation_messages) {
	//Skip loop if the key is for the timestamp
	if (key == "timestamp") continue;
	
//4. Check each task for a file_exists_test field
//	 a. If it doesn't exist then continue
if (validation_messages[key].pdf_optimization_test != 1) {

//5. Create the pdf_optimization_test and set to 1.
validation_messages[key].pdf_optimization_test = 1

//6. extract all leafs from index and regional sections
test = validation_messages[key].payload

temp0 = temp0.concat(test.index)
temp0 = temp0.concat(test.regional)

temp1 = temp0.length;
    for (var i = 0; i < temp1; i++) {
        console.log(temp0[i][7] + " - " + temp0[i][9])
      nmsg = {}
    nmsg.payload = temp0[i][3]
    nmsg.tracking = [temp0[i][3],temp0[i][4],temp0[i][6],temp0[i][7],temp0[i][8],1,temp0[i][9]]        

if(temp0[i][9] != 0) {
node.send([[null], [nmsg]]) 
}else if(temp0[i][4] == "pdf") {
node.send([[nmsg], [null]]) 
} else {
       node.send([[null], [nmsg]]) 
}
    }
} else {continue;}

}
return

Global context structure (if this helps or is even understandable):

multiple objects{ timestamp: integer
random name (multiple): {

timestamp: integer
multidimensional object
multidimensional object
4 text entries
object{two objects with identically formatted content
object{
array [ multiple sub array elements
array [ 14 elements.  9, 10 ,11 are lost]
]
}
}
}

I suspect it is 0 and skips the rest of our loop ?

I don't know if this will matter but remember

When trying to create copies of the values inside variables in JavaScript it is very important that you understand the difference between passing by value and passing by reference.
see https://www.youtube.com/watch?v=duyshh9Fs1U

I tracked down the problem.

I had set up a race condition in a previous node. The first msg to come through triggered the process before everything else arrived. By the time I looked all the data was present but the node had already run on the task and marked it as complete so incorrect data was being processed.

I added a test for completeness on the previous step and everything worked..

Thank you for the support!

1 Like