Hey hey @AlexSavchuk !
Thank you so much for your reply, I am using the monday-sdk in nodeJs to fetch an array from an external XML file.
Then it checks if the ID from the array exist in an number column on the board, if it does update column values, if it doesnt exist create new item.
Everything here works as it should exept that the values from the hour columns both disappears when i refresh the page. When i log the output from the changeColumnValue it sends it as it should.
I have simplefied some of the code here, but i have validated that the issue still occurs.
monday-controller.js:
const mondayService = require('../services/monday-service');
const xmlService = require('../services/xmlRead-service');
async function addDataToBoard(req, res) {
const { shortLivedToken } = req.session;
const { payload } = req.body;
try {
const { inputFields } = payload;
const { boardId, groupId, xmlLink, dataIDColumnId, targetTime, targetNumber} = inputFields;
//Get data data
const fetchData = await xmlService.queryXMLData(xmlLink);
fetchData.forEach(async getData =>{ // Run for all IDs
const listAllColumnWithID = await mondayService.getItemByColumnValue(shortLivedToken, boardId, dataIDColumnId, ""+parseInt(getData.$.id)+"", 1);
if(listAllColumnWithID.toString()){ //If ID Exist on board, update values.
let mondayItemIdToUpdate = listAllColumnWithID.map(({ id }) => id).toString(); // Item ids from monday that have
//Update column values.
await mondayService.changeColumnValue(shortLivedToken, boardId, parseInt(mondayItemIdToUpdate), targetTime, JSON.stringify({"hour": parseInt(getData.Time_of_event).toString().substring(0,2),"minute": parseInt(getData.Time_of_event).toString().substring(2,4)}));
await mondayService.changeColumnValue(shortLivedToken, boardId, parseInt(mondayItemIdToUpdate), targetNumber, "\""+parseInt(getData.Number_of_available_seats)+"\"");
} else { // If ID doesnt exist on board, create new item.
//removed to simplify.
};
});
return res.status(200).send({});
} catch (err) {
console.error(err);
return res.status(500).send({ message: 'internal server error' });
}
}
mondayService.changeColumnValue:
const changeColumnValue = async (token, boardId, itemId, columnId, value) => {
try {
const mondayClient = initMondayClient({ token });
const query = `mutation change_column_value($boardId: Int!, $itemId: Int!, $columnId: String!, $value: JSON!) {
change_column_value(board_id: $boardId, item_id: $itemId, column_id: $columnId, value: $value) {
id
}
}
`;
const variables = { boardId, columnId, itemId, value };
const response = await mondayClient.api(query, { variables });
return response;
} catch (err) {
console.error(err);
}
};
mondayService.getItemByColumnValue:
const getItemByColumnValue = async (token, boardId, columnId, columnValue, limit) => {
try {
const mondayClient = initMondayClient();
mondayClient.setToken(token);
const query = `query($boardId: Int!, $columnId: String!, $columnValue: String!, $limit: Int!) {
items_by_column_values(board_id: $boardId, column_id: $columnId, column_value: $columnValue, limit: $limit) {
id
}
}`;
const variables = { boardId, columnId, columnValue, limit };
const response = await mondayClient.api(query, { variables });
return response.data.items_by_column_values;
} catch (err) {
console.error(err);
}
};
I have sendt you a message with a link to a quick video how it looks on the board.
Thanks.
-Sindre