My Products
Help
magnusalex
PARTNER

API returns "Primary key already exists", but batch is still created

by magnusalex

Hi,

 

Simple batch_create query/mutation: 

 

 

mutation batch_create($cid: Int!, $date: Int!, $desc: String!)
{
   useCompany(no: $cid)
   {
      batch_create(
         values: [{
            valueDate: $date,
            description: $desc
         }],
         suggestValues : {
          batchNo: {
            type: INTERVAL
            from: 1000
            to: 99999
          }
        }
         )
      {
         affectedRows
         items
         {
            batchNo
         }
      }
   }
}

 

 

 

{
    "cid": ***,
    "date": 20220923,
    "desc": "Test"
}

 

 

This returns the following: 

 

 

{
    "errors": [
        {
            "message": " Description: A record with the same primary key already exists.. Status: 3."
        }
    ],
    "data": {
        "useCompany": {
            "batch_create": null
        }
    },
    "extensions": {
        "vbnxt-trace-id": "***"
    }
}

 

 

But the batch is still created. Am I forgetting something, or is this an error in the API? 

 

The batch in VB NXT: 

 

Skjermbilde 2022-09-23 kl. 11.12.05.png

 

Thank you!

Magnus

5 REPLIES 5
Accepted solution
Marius Bancila
VISMA

by Marius Bancila

We have release a fix to production that should solve your problem.

 

However, notice that we have deprecated the suggestValues argument in favor of a new way of suggesting values. Please check the documentation here: https://docs.business.visma.net/docs/schema/mutations/inserts#suggested-values. Existing queries will continue to work for a while, but the interval suggestion is only considered for the few columns that support it. The batchNo column is not one of them, so a single suggest value is automatically used instead.

magnusalex
PARTNER

by magnusalex

Great! Thank you 🙂 

by Marius Bancila (Updated ‎30-09-2022 16:41 by Marius Bancila VISMA )

At least one problem is that you cannot actually suggest a value in an interval for batchNo. This is not properly indicated in our API. I will try to see how to make this less error prone.

magnusalex
PARTNER

by magnusalex

Thank you for clarifying!  

by Marius Bancila

We are investigating this problem and will return with comments as soon as we have a solution.