ServerConnect too fast to pull acurate data

Good morning Everyone,

I have a Server Connect function that creates a purchase order in our Wappler project, it then combs through all of the Sales Order lines and goes to create them under that purchase order. The only problem that I’ve noticed is that the LineNo which increases by 10 each Purchase Order line, sometimes wappler is not able to pull the correct number because it is being created IMO too fast enough.

The SQL function that pulls the LineNo is below.

Is there something that I’m missing when pulling the next line number? I’ve tried to add a wait, maybe this will also PSQL to update and then it will query with the correct data, however this too causes the same problem.

Hi, I doubt the problem is with the SELECT, it’s something that happens before. This is called a race condition, you would need to share a screenshot of your Server Action. You only have 1 server connect call in this entire process?

There are multiple Database actions in the Server Connect that gets the next LineNo. However the SELECT query is inside 2 double repeat.

Ok… What if you move the Transaction to before the repeatOrderLines? So all order lines are created in the same transaction

The repeatOrderLines repeat is what creates the order lines. Before that would be the repeatSuppliers which then would default to all LineNo being 10.

I don’t know what could be the problem, hope you can figure it out :slight_smile:

Gut feeling it it may be caused by the API action step.
Take a look at the developers console and see how long it is taking to respond then try adding a wait (it's in core actions) to allow it to complete.

1 Like

Hey guys,

@astroGlide i noticed in your output screenshot that the getPurchaseOrderHeader is running only in the first loop then not…

Is that normal?

I don't see any condition there…

*a quick view from mobile.. Ignore me if not correct/accurate

I added a delay of 1750 misecs however this only caused the server connect to time out.

@famousmag - You are correct, I also rerun the server connect and noticed in the first repeat it doesn’t run the getNextLineNo query and so the variable “nextLineNo” is calculated with a null value + 10. Hence why the result is 10. It only runs the query to find the next line number once it processes 2 repeats.

Network Result:

Application Result:

image

I’m now thinking that this is the main reason why the numbers are not being assigned as they should. Is it normal for ServerConnect to skip and select which actions it should run?

@astroGlide I would try to get the output from every step along with a timestamp so I can see which line is running, when and what it outputs (result)

I thing there is NO SUCH A CASE like server action skips by itself steps or similar scenarios…

The solution is behind your code, hidden between the lines of your steps!

Break every step of your server action and try to understand what each step is returning and in which order this is happening…

Most of the times we suppose that everything is running the way we think… but we must make sure that it is!

2025-09-25T14:53:29.252Z server-connect:output repeatOrderLines: [
  {
    getPurchaseOrderHeader: {
      id: '46e98fcd-9a07-4e60-8a5e-547c9f841b8c',
      documentNo: '245227',
      orderType: 'DR',
      entryMethod: 'DR',
      supplierRemitNo: 102508,
      linkSalesOrder: 1845783,
      odrDate: '2025-09-25',
      requestedDate: '2025-07-22',
      status: 'DF',
      fulfillmentType: 'D',
      region: 'DATL',
      brandId: null,
      brandName: null,
      odrTotal: null,
      supplierContact: null
    },
    getNextLineNo: undefined,
    nextLineNo: 10,
    getPurchasePrice: { status: 200, headers: [Object], data: [Object] },
    purchasePrice: 4188,
    extendedPrice: 8376,
    createPurchaseOrderLine: { affected: 1, identity: 'f19cd5bf-bb8e-4af5-a42b-185137d9f8ed' },
    CreatePOLines: undefined
  },
  {
    getPurchaseOrderHeader: undefined,
    getNextLineNo: undefined,
    nextLineNo: 10,
    getPurchasePrice: { status: 200, headers: [Object], data: [Object] },
    purchasePrice: 4188,
    extendedPrice: 8376,
    createPurchaseOrderLine: { affected: 1, identity: '1ded2751-d7e6-4982-951f-8436504dc31e' },
    CreatePOLines: undefined
  },
  {
    getPurchaseOrderHeader: undefined,
    getNextLineNo: undefined,
    nextLineNo: 10,
    getPurchasePrice: { status: 200, headers: [Object], data: [Object] },
    purchasePrice: 4859,
    extendedPrice: 9718,
    createPurchaseOrderLine: { affected: 1, identity: '856405eb-d3bc-418a-ac32-08cab8537164' },
    CreatePOLines: undefined
  }
]

I believe I have found the bottleneck in the code. It seems like it’s only pulling “getPurchaseOrderHeader” only once and only applying it to the first repeat. This would explain why the value for the nextLineNo is always 10 because it defaults to an empty value when pulling “getNextLineNo”. Can anyone provide any fix to this, below is the server connect actions for this repeat: