Solved

GraphQL: Creating New Card via ConnectionField Update


Userlevel 6
Badge +1

I’ve got a bit stuck with this one in GraphQL.

Background:

I want to update a card which has a required connectionField (you need to create a new card, not link to an existing one). This ConnectionField is to a Pipe, where the start form has some required fields.

GraphQL:

I’ve been looking at using updateFieldsValues to achieve this, but don’t find how to:

  1. Update the conneciton field - which is equal to adding a new card via this connection field
  2. Filling in the required fields in this new card (so that it successfully is created)

Appreciate any pointers or direction on this. If I haven’t made it clear enough please let me know, and I’ll improve the explanation.

icon

Best answer by genietim 6 October 2022, 19:59

View original

11 replies

Userlevel 6
Badge

Hello, how are you? In this case the creation would be of a connected card? If so, please try using this querry and tell me if it was possible?

mutation {

createCard(

input: {pipe_id: 302484445, fields_attributes: [{field_id: "test_api", field_value: [450307915]}, {field_id: "test_2", field_value: "hi2"}, {field_id: "task_title", field_value: "ball"}]}

) {

clientMutationId

}

}

Userlevel 6
Badge +1

Hi @natalia-manffre 

Thanks for this. So it looks like you’re saying this can be approached differently.

  • Step 1: Create the new card (with the code you pasted)
  • Step 2: Connect the new card created to the connected field

Did I understand you correctly?

I ask because currently this Pipe only allows the creation of cards from the connected field - not search and attach. So I don’t think that will work with this current set up.

Userlevel 7
Badge +12

In my memory, it indeed does not matter: you can use the createCard mutation, the createCardRelation mutation and/or the update field(s/values) mutation to connect the two cards. The “only allows the creation of cards from the connected field - not search and attach” restriction is just a front-end restriction to my knowledge.

In case it changes (changed?) some day, I would recommend to look at the queries Pipefy does using the Network tab in the developer console of your browser. There, when you enact the desired sequency of actions (i.e., create the connected card, update the field), you could see what series of queries is necessary to achieve your goal.

Userlevel 6
Badge +1

Thanks @genietim 

Working on it/ will let you know how it goes.

Userlevel 6
Badge

Hi @Keto-Faster  after the answer from @genietim  did it work for you this API?

Userlevel 6
Badge +1

Hi @natalia-manffre @genietim 

Unfortunately I have not been able to create cards with attached fields - I am getting errors. So I resorted to removing the ‘required’ on the connection fields for testing and linking them with createCardRelation afterwards, however, am still running into trouble.

Example Error

Error 30003 Validation failed: Source Source Field is not connected to repo 302727453

This is the GraphQL

mutation {

createCardRelation(

input: {
childId: ID,  // the child id is added here
parentId: ID, // the parent ID is added here
sourceId: 344416146,  // the internal field id is added here
sourceType: "Field"
       }

) {


clientMutationId

}

}

Not sure where this is going wrong. Would appreciate any thoughts.

Userlevel 7
Badge +12

The error indicates that the child was created in a pipe/table that is not the one connected to the field.

Not sure how to help here - either I’d have to ask for more exact details about your setup, or just again recommend to look into the network tab in the browser to see what queries Pipefy does exactly, maybe you find a difference between some repo or sourceId or something there (as, admittedly, they seem to be using slightly different mutations for certain things). See screenshot below.

 

 

Userlevel 6
Badge +1

Ok, good news @genietim. Thanks for your help.

I got past everything and it went through. The connection shows up in Pipefy now, BUT… it doesn’t show on the ConnectedField. It shows at the top left of the card that the connection is established, but it isn’t on the field.

I’m not sure how this is working @natalia-manffre perhaps you have an idea here, as I specified the internal id of the specific field and that it should connect at the Field level? 

This Creates the Card

This Relates the Card to that Card

mutation {

createCardRelation(

input: {
childId: {{180.id}},
parentId: {{81.id}},
sourceId: 344416146,
sourceType: "Field"
       }

) {


clientMutationId

}

}

 

Screenshot - you can see that “CRITERIA SET” has nothing connected to it. But the card “Company” is connected to this Card in “CRITERIA SET”.

 

Userlevel 7
Badge +12

Have you tried to set the connected card explicitly with the updateCardField or updateFieldsValues, respectively?

e.g.
 

mutation {

updateCardField (input {

card_id: theParentCardId,

field_id: theFieldIdButNotTheInternalOne,

new_value: [ theIdOfTheCardToConnect ]

}) {

clientMutationId

}

}

 

Userlevel 6
Badge +1

That got it @genietim - I used the updateCardField - thanks!

So I’ve got it working without the ‘required’ attribute on for the Connection Field now. That’ll be fine for the moment, can figure out how necessary required is/ and if there is a workaround for it.

So the full approach was:

  1. Create Child Cards First (createCard)
  2. Add to Parent Card with updateCardField Last
Userlevel 7
Badge +12

What error do you get with your – now working – approach when you reinstantiate the required attribute?

Respectively, no, I think I just understand now where you have a required attribute, shoudn’t you just set the connected field’s value when creating the parent card to the “

[ theIdOfTheCardToConnect ]

”, instead of only afterwards with the updateCardField?

Reply