Adding a UDID to an existing invoice

103 views
Skip to first unread message

Dan Palley

unread,
Jul 18, 2017, 4:22:43 PM7/18/17
to TramsAPI Beta
If we want to write data back to the API (inserts/updates/deletes), we need to create what's called a delta dataset.  The delta dataset represents the changes we want to make to the underlying data.

The format of the delta dataset is similar to the normal dataset we get back when calling the load method, with a few changes. 

First of all, for each record, we need an action code.  The action code can be insert, update, delete, or none.  An action code of none is used to indicate which child records to update; no updates will be done to the table itself. When using none, you only need to specify the fields that are part of the primary key for the table, although you can specify all fields if you'd like.  For example, if we want to make changes to booking 1 which is part of invoice 1, we would create a delta dataset like this:

  "DELTADATASET":{
    "Invoice":[
      {
        "NONE":{
          "InvoiceNo":1,
          "Booking":[
            {
              "NONE":{
                "BookingNo":1
              }
            }
          ]
        }
      }
    ]
  }

Now we can add the insert action for the UDID table below the booking table:

"UDID":[
  {
    "INSERT":{
      "UDIDNo":5,
      "Booking_LinkNo":1,
      "Invoice_LinkNo":1,
      "UDID":"test5555"
    }
  }
]

So we end up with this:

  "DELTADATASET":{
    "Invoice":[
      {
        "NONE":{
          "InvoiceNo":1,
          "Booking":[
            {
              "NONE":{
                "BookingNo":1,
                "UDID":[
                  {
                    "INSERT":{
                      "UDIDNo":5,
                      "Booking_LinkNo":1,
                      "Invoice_LinkNo":1,
                      "UDID":"test5555"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  }

(also see attached InsertUDID.JSON)

The above JSON tells the API to insert a UDID record with UDID number of 5 and a value of "test5555" into booking 1 which is part of invoice 1.

We would then make the call to Invoice.ApplyUpdates and pass in our session ID, and the delta dataset.

Dan
insertudid.json

bill

unread,
Jul 20, 2017, 12:49:12 PM7/20/17
to TramsAPI Beta
Hi Dan,

The UDID program I have now to update or add a udid doesn't always know which action.  Currently I try to add a udid and then check for an error (already exists) and then I do an update to the udid.

Can you give me an idea how that would work with the api?  Or would it be better to query for the udid first and then decide whether to update or insert?

Bill

Dan Palley

unread,
Jul 20, 2017, 1:54:06 PM7/20/17
to TramsAPI Beta
Hi Bill,

I would suggest you load the entire invoice and see if the UDID already exists for the booking(s), then either do the insert or update.

Dan
Reply all
Reply to author
Forward
0 new messages