I am surprised about how you need to set the patch items of an update for making the update runs without error.
I write a dataconnector for retrieving document list and Initially I used this code for the key to the patch without success:
itemsPatch.set(
apiDocument.documentId, convertToDocument(apiDocument as ApiDocument),
)
Full code:
export const getDocumentListAction = async (action: DataConnectorAsynchronousAction) => {
const apiDocuments = await searchDocuments(action.context.userCredential);
const itemsPatch = new Map<string, SerializedFields>();
var i = 0;
apiDocuments?.forEach((apiDocument) => {
itemsPatch.set(
apiDocument.documentId, convertToDocument(apiDocument as ApiDocument),
);
});
if (apiDocuments) {
action.client
.update({
dataSourceName: "Lucid",
collections: {
"Lucid Documents": {
patch: {
items: itemsPatch,
},
schema: documentSchema,
},
},
})
.catch((error) => {
console.error(
"Error encountered when updating Lucid Documents of Lucid collections",
error
);
});
}
return {
success: true,
};
};
After several days of searching why it was not working, I used
this in adding quote to the key which, for me, seems strange as apiDocument. documentId is already a string:
itemsPatch.set(
"\"" + apiDocument.documentId + "\"", convertToDocument(apiDocument as ApiDocument),
)
Full code
export const getDocumentListAction = async (action: DataConnectorAsynchronousAction) => {
const apiDocuments = await searchDocuments(action.context.userCredential);
const itemsPatch = new Map<string, SerializedFields>();
var i = 0;
apiDocuments?.forEach((apiDocument) => {
itemsPatch.set(
"\"" + apiDocument.documentId + "\"", convertToDocument(apiDocument as ApiDocument),
);
});
if (apiDocuments) {
action.client
.update({
dataSourceName: "Lucid",
collections: {
"Lucid Documents": {
patch: {
items: itemsPatch,
},
schema: documentSchema,
},
},
})
.catch((error) => {
console.error(
"Error encountered when updating Lucid Documents of Lucid collections",
error
);
});
}
return {
success: true,
};
};
Any explanation?
Regards.