Workflow : Count number of objects
Hello, when a "Company" is updated, I want to update the number of Inks (it's a custom object) associated.
So I created a workflow with a serverless code but I struggle to access to this "inks" object
If I launch this :
query MyQuery {
companies(filter: {name: {eq: "Diamine"}}) {
edges {
node {
id
name
inks {
countNotEmptyId
}
}
}
}
}
I get this :
{
"data": {
"companies": {
"edges": [
{
"node": {
"id": "6ce1408b-7b4e-444a-9a79-2a4dd8541569",
"name": "Diamine",
"inks": {
"countNotEmptyId": 163
}
}
}
]
}
}
}
Is there a way to do get this "countNotEmptyId" using a serverless function ?14 Replies
Please correct me if I'm wrong: company and inks have relation between each other and you want to find all inks which have relation to company named Diamine?
Exactly ! A company can have many Inks
🤔
Let me check something
I want to update a field "ink_count" for every company "updated". I can access company simple objects (name, id..) but I don't know how to access this "inks" object
I did this very simplified code
Thanks bob
I have no problem using external API, but I try to access this object using the workflow serverless function.
Defaut function is :
export const main = async (params: {
a: string;
b: number;
}): Promise<object> => {
const { a, b } = params;
// Rename the parameters and code below with your own logic
// This is just an example
const message = Hello, input: ${a} and ${b};
return { message };
};
But I don't find how to access company "inks" in this function.
Ah, I see, that's not possible
To simply put, relation with objects is called nested field and nested fields and filters will be done in Q1 26 https://github.com/twentyhq/core-team-issues/issues/214
GitHub
👁️ Nested Fields · Issue #214 · twentyhq/core-team-issues
About In a database, a "Customer" object might have a relation to an "Order" object. Using nested fields, you can display details of an order (like order date or total amount) d...
So for time being, there's no other way than sending a request through API and parsing the data
Oh, ok, I thought as it is a One (Company) to Many (Inks), it was possible to link them togther. As I can access them using API, I don't see why I cannot from serverless code, it's based on the API as well, no?
I don't know, @thomast? 😅
Thank you for the ping @bob!
Hi @greg [iero], we do not support one to many relationships in variable picker, only many to one. This is not based on API.
What you can do is doing first a code step to perform an api call to twenty to retrieve the inks associated to the company via API.
Alternatively you can:
- enable workflow iterators in lab
- add a find record node, enabling the iterators in lab will remove the limit
- retrieve the inks associated to the company but using the find record node
Thanks for the clarification, I think I will use the API then to update the field