T
Twenty2mo ago
ap0st0L

Updated By field?

Hi, Im creating some basic workflow to send a notification when someone update a record (a task), but I can not see how to get who made the last update... just who create the record. How can I access to who made the last change on some record? Right now my code block are making this query: query SearchUserByID($userId: UUID!) { workspaceMembers(filter: { id: { eq: $userId } }, first: 1) { edges { node { id userEmail name { firstName lastName } } } } } Thanks.
34 Replies
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
It's not possible since there's no updatedBy field, only updatedAt The basic way would be to create a relation type field to workspace member records (belongs to one) and create a workflow that basically every time any record of this object is updated, it'll update the previously created field with workspace member who did that
ap0st0L
ap0st0LOP2mo ago
Thanks. I will try something like that.
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
The only problem is that workflow will be limited to only one object so if you want to extend this to more objects, you have to create the same workflow for more of them
ap0st0L
ap0st0LOP2mo ago
I see the option to export a workflow... where can I import one? (so I can duplicate a workflow)
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
I don't think there's one, @thomast? Technically it's possible to do it even easier with apps as now Twenty slowly has more extensions to do it, so you can also create an app which do it automatically, problem is it'll be also limited to one type of object like workflows and can result in accidental DDoS due to recursion EDIT: Nvm, for now it's not possible, recursion will happen @ap0st0L I can prepare a plugin/app which will automatically update the field in all objects once type of updated object is exposed to apps, although I can't say when exactly it'll be available as distribution of apps is in very early stage EDIT: another problem appears that when trying to create a relation field via API as it's currently unsupported, so there's nothing I can do until core team adds a possibility
Prastoin
Prastoin2mo ago
EDIT: another problem appears that when trying to create a relation field via API as it's currently unsupported, so there's nothing I can do until core team adds a possibility
You should be able to create any fied you want through the API, maybe there's an assymetry between the rest and graphql one relation field creation Could you please share any errors while creating a relation field through the REST API ?
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
No description
Prastoin
Prastoin2mo ago
That seems to be a rest issue Could you please double check that you can create this using gql resolver ?
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
Don't think so I reported the problem regarding GraphQL that it doesn't expose standard object, only few custom ones I'll try either way
Prastoin
Prastoin2mo ago
So the issue is not creating a relation field but rather creating a relation field on a standard object ?
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
The issue is creating a relation field without actually being able to specify the relation between which objects as relation object isn't exposed in REST API
Prastoin
Prastoin2mo ago
What I'm trying to mean is that creating a relation field does not seem to be broken atm Ok I see
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
And when I try to create one without using relation object in request data, this is returned
No description
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
And how do I create something via GraphQL? 😅
Prastoin
Prastoin2mo ago
Will share a video on how to do so in ~5 mins
Prastoin
Prastoin2mo ago
From graphql api playground - Add a new mutation - Find the mutation you want click on it and select what you want to send - define either variables or manually write static input in the mutation
No description
No description
Prastoin
Prastoin2mo ago
I think the REST api validator does not map the field metadata type correctly
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
🤔 I'll check REST validator later, now I'm trying to figure out relationCreationPayload
Prastoin
Prastoin2mo ago
If you want you can get an example by creating one in the UI Atm quite busy srry
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
And look it up in Network tab 👍 No problem, thanks for your help
Prastoin
Prastoin2mo ago
Nw ! let me know
ɃØĦɆᵾS
ɃØĦɆᵾS2mo ago
I don't really have an idea how to bypass a JSON limitation as - createOneField offered by GraphiQL accepts only string but giving stringified JSON returns an error - createOneMetadataFieldItem found in Network tab accepts JSON but when everything is transferred to GraphiQL, it shows that relationCreationPayload should be JSON (but I guess it interprets as object?), when sent like this or stringified, it returns an METADATA_VALIDATION_FAILED error Okay, found my way, nasty and not really proud but working In short, literally copy pasting the payload from Network made it work so that's something but finding a way through it can be quite annoying
Prastoin
Prastoin5w ago
Hey, I would recommend settings variable for formatting the relationCreationPayload
Prastoin
Prastoin5w ago
To copy vars and query as highly replayable
ɃØĦɆᵾS
ɃØĦɆᵾS5w ago
I'll try it Okay, that worked, thanks for help!
Prastoin
Prastoin5w ago
Congrats !
ɃØĦɆᵾS
ɃØĦɆᵾS4w ago
@Prastoin there's another problem, updating relation field via API results in error https://github.com/twentyhq/twenty/pull/15513#issuecomment-3481672609
GitHub
[HACKTOBERFEST] Updated by extension by BOHEUS · Pull Request #155...
This PR adds Updated by extension which creates "Updated by" relation type field to workspaceMembers records if it doesn't exist and updates it whenever user changes somet...
Prastoin
Prastoin4w ago
What are you trying to update on the relation field ? Relation field edition is forbidden by definition
ɃØĦɆᵾS
ɃØĦɆᵾS4w ago
Update the workspace member id to show who's responsible for last changes Wait, really? Why?
Prastoin
Prastoin4w ago
Updates on a UUID field should not be an issue But you can edit anything on a relation field for the moment ( even the label and desc 😛 in coming soon ) because it break to many indexes under the hood in db
ɃØĦɆᵾS
ɃØĦɆᵾS4w ago
In the API?
Prastoin
Prastoin4w ago
What in the api ?
ɃØĦɆᵾS
ɃØĦɆᵾS4w ago
This Nvm, understood, was thinking about something else I'll send my GraphQL and REST API payloads once I'm back to show and check if I'm doing something wrong REST API payload to PATCH /post/{objectName}/{id}
{
updatedById: `${userId}`,
}
{
updatedById: `${userId}`,
}
GraphQL API payload (taken from Network tab and modified to be generic)
mutation UpdateObject($idToUpdate: UUID!, $input: ${objectSingularName}UpdateInput!) {
update${objectSingularName}(id: $idToUpdate, data: $input) {
id
updatedById
}
}
################### VARIABLES
{
"idToUpdate": recordId,
"input": {
"updatedById": userId
}
}
mutation UpdateObject($idToUpdate: UUID!, $input: ${objectSingularName}UpdateInput!) {
update${objectSingularName}(id: $idToUpdate, data: $input) {
id
updatedById
}
}
################### VARIABLES
{
"idToUpdate": recordId,
"input": {
"updatedById": userId
}
}

Did you find this page helpful?