When selecting the data from the MySQL database, If there is no data returned how can I change the response as a JSON message instead of “No text data found”
This will be helpful for using IF Node next to it.
I tried enabling this option. But it is just an empty array.
Hi @mcnaveen , you could check for a field that should have been returned in your IF node. E.g. a simple check could be whether the username field is empty using an expression of {{$json["username"]}} in your IF node.
If a user has been returned, the item would go to the false output (because the username field is not empty):
If there is no user, the empty item would go the true output:
You could then connect a Set node to the true output of your IF node to convert this empty JSON into a JSON with the fields you’d like to see.
Oh wow.
Never checked Is Empty under IF Node.
This is nice, Thanks for your response
Awesome, glad to hear this helps and thanks a lot for confirming
There is an issue with this approach.
This is my workflow. If the data is returned from the MySQL node. It’s working properly.
But when there is no data. If Node isn’t processing anything.
Here is my workflow
If MySQL node returns No text data found as JSON response. It’ll be a lot easier.
I tried adding Else block after this to turn into JSON response. But I might be doing it wrong.
const rawQuery = this.getNodeParameter('query', index) as string;
return connection.query(rawQuery);
});
const queryResult = (await Promise.all(queryQueue) as mysql2.OkPacket[][]).reduce((collection, result) => {
const [rows, fields] = result;
if (Array.isArray(rows)) {
return collection.concat(rows);
}
collection.push(rows);
return collection;
}, []);
returnItems = this.helpers.returnJsonArray(queryResult as unknown as IDataObject[]);
} catch (error) {
if (this.continueOnFail()) {
In your example the “Always Output Data” option appears to be disabled (which was previously enabled as per your screenshot further up):
That’s be why the workflow doesn’t continue here.