I have a connection field that already has a connection in it and I need to add another connection with ajax PUT and for the life of me cannot figure out the syntax. It’s a many-to-many table.
I can successfully PUT one connection into the non-raw field and it works fine. If am replacing whatever is in the connection field, I only have to send the connection and not the identifier for it to work.
var UpdateActivitiesObject = {
“field_381”: NewBatchConn
};
But I need to add a connection to what is already there. So I am first reading what the existing connection is, then trying to combine with the new connection and then put both together.
A simpler way of stating my question is this:
The existing connection field_381 has this object in it:
[
{"id":"636c257824dc630021195225","identifier":228},
{"id":"636c20ea52a340002567277b","identifier":223},
]
I want to add another value to the list. How do I format it? I imagine something like this but it doesn’t work.
"field_381": '{"636c257824dc630021195225"}, {"636c20ea52a340002567277b "}, {"636c1957fdda4100211083bb "}'
DETAIL
If I try using the non-raw field, the existing data looks like this
<span class="636c1734fdda410021106e71">215</span><br /><span class="636bfe9c13cf0800233d2327">204</span>
So I have tried to replace it with this
<span class="636c1734fdda410021106e71">215</span><br /><span class="636bfe9c13cf0800233d2327">204</span><br /><span class="636c179b48ef7a002178b661">216</span>
And yet that doesn’t work. The field gets updated with nothing.
I also tried putting the raw version of it into an array, pushing the new values in, then PUTting the new array but it does not seem to want to accept an array at all.
//look FOR existing batch value and APPEND new one to it.
DoSomeAjax(ActivitiesUpdateURL, 'GET', '', function(ActivityBatch) { // custom function, it works
// get current Batch value
ExistingBatches = ActivityBatch.field_381;
if (ExistingBatches.length > 0) { // if Batches is not null, append
// if there are any, array will look like this
// 0:{id: '636c0120f72fd500210e43a5', identifier: 205}
// 1:{id: '636bfc554c688a0021f3f731', identifier: 203}
// for purposes of this forum,
NewBatchID = '216';
NewBatchConn = '636c179b48ef7a002178b661';
BatchArray = ActivityBatch.field_381_raw; // get what is already in the array
BatchArray.push({id: NewBatchConn, identifier: NewBatchID});
// set up the data variable here
var UpdateActivitiesObject = {
"field_381_raw": BatchArray
};
DoSomeAjax(ActivitiesUpdateURL, 'PUT', UpdateActivitiesObject, function(object10update) {
console.log(object10update);
// do other stuff
});
}
Is there something else I can try?? Thank you.