Add ANOTHER connection using the API and jQuery

I finally figured it out so am posting for anyone else who needs to ADD CONNECTIONS to a field that already has some connections in it:

It was very confusing because what would come OUT OF the existing array was not the same way that I needed to put it back in! I had to

  • Read the existing connections from the raw connection field
  • Extract ONLY the id from each record
  • Put each existing ID into a temporary array
  • Add the new ID to the temporary array
  • Send the temporary array in my JSON object and put into the NON-RAW field
// get what is already in the RAW array
CurrentArray = MyData.field_381_raw;    
// existing raw array looks like: [{"id":"6377f36b0f0d26002179f1e2","identifier":273}]

// extract connection (ONLY) from existing array and put into new simpler array
NewArray = [];  
for(var a =0; a <CurrentArray.length; a++){
     NewArray.push(CurrentArray[a]['id']);        // take only the id, not the identifier
}

// add the newest value
NewArray.push(NewConn);                  
// looks something like ["4fea069e9e8246001d000698", "4fea069e9e8246001d000699"]

// send them all together into the NON-RAW field
var UpdateActivitiesObject = {
    "field_381":NewArray
};
1 Like