Basic Examples DocumentChange operations on rows

Dokumentation •
In diesem Artikel

Example adding a row

The following example shows how to append a row to the Transactions table. If you indicate the sequence, the row will be inserted at the given position. Try this operation


{
   "format":"documentChange",
   "error":"",
   "data":[
      {
         "document":{
            "dataUnits":[
               {
                  "data":{
                     "rowLists":[
                        {
                           "rows":[
                              {
                                 "fields":{
                                    "Date":"2019-01-04",
                                    "Description":"Invoice 304"
                                 },
                                 "operation":{
                                    "name":"add"
                                 },
                                 "style": {
                                    "fontSize":12,
                                    "bold":"true",
                                    "italic":"false"
                                 }
                              }
                           ]
                        }
                     ]
                  },
                  "nameXml":"Transactions"
               }
            ]
         }
      }
   ]
}

Example modifying a row

The following example shows how to modify the existing row at line 2 in the Transactions table.


{
   "format":"documentChange",
   "error":"",
   "data":[
      {
         "document":{
            "dataUnits":[
               {
                  "data":{
                     "rowLists":[
                        {
                           "rows":[
                              {
                                 "fields":{
                                    "Description":"Invoice Hello World"
                                 },
                                 "operation":{
                                    "name":"modify",
                                    "sequence":"1"
                                 }
                              }
                           ]
                        }
                     ]
                  },
                  "nameXml":"Transactions"
               }
            ]
         }
      }
   ]
}

Example replacing a row

The following example shows how to replace the existing row at line 2 in the Transactions table.


{
   "format":"documentChange",
   "error":"",
   "data":[
      {
         "document":{
            "dataUnits":[
               {
                  "data":{
                     "rowLists":[
                        {
                           "rows":[
                              {
                                 "fields":{
                                    "Date":"2020-01-05",
                                    "Description":"Invoice 304",
                                    "Amount":"300.00"
                                 },
                                 "operation":{
                                    "name":"replace", 
				    "sequence":"1"
                                 }
                              }
                           ]
                        }
                     ]
                  },
                  "nameXml":"Transactions"
               }
            ]
         }
      }
   ]
}

Example deleting a row

The following example shows how to delete the existing row at line 2 in the Transactions table.


{
   "format":"documentChange",
   "error":"",
   "data":[
      {
         "document":{
            "dataUnits":[
               {
                  "data":{
                     "rowLists":[
                        {
                           "rows":[
                              {
                              "operation": {
                              "name": "delete",
                              "sequence": "1"
                                 }
                              }
                           ]
                        }
                     ]
                  },
                  "nameXml":"Transactions"
               }
            ]
         }
      }
   ]
}

Example moving a row

The following example shows how to move the existing row at line 2 to line 5 in the Transactions table.


{
   "format":"documentChange",
   "error":"",
   "data":[
      {
         "document":{
            "dataUnits":[
               {
                  "data":{
                     "rowLists":[
                        {
                           "rows":[
                              {
                                 "operation":{
                                    "name":"move",
                                    "sequence":"1",
                                    "moveTo":"4"
                                 }
                              }
                           ]
                        }
                     ]
                  },
                  "nameXml":"Transactions"
               }
            ]
         }
      }
   ]
}

Example adding rows to recurring transactions table

The following example shows how to add rows to the table Recurring transactions.


{
  "format": "documentChange",
  "error": "",
  "data": [
    {
      "document": {
        "dataUnits": [
          {
            "data": {
              "rowLists": [
                {
                  "nameXml": "Templates",
                  "rows": [
                    {
                      "fields": {
                        "Date": "20200705",
                        "Description": "compleanno Anna",
                        "Doc": "r1"
                      },
                      "operation": {
                        "name": "add"
                      }
                    }
                  ]
                }
              ]
            },
            "nameXml": "Transactions"
          }
        ]
      }
    }
  ]
}

Example adding JSON content in a custom column in the Transactions table

DocumentChange allows you to update a MIME field of type text/json. In this field it is possible to insert several json objects identified by a key.

  • The contents of the field must be passed as a string
  • Other types of MIME fields (text/html, image/jpg, ...) are currently not supported.
  • In Banana you can create a column of type MIME using the menu command: Data - Columns setup, Add new column and choosing Data type Mime

{
  "format":"documentChange", 
  "error":"",
  "data": [
    {
      "document": {
        "dataUnits": [
	  {
	    "data": {
               "rowLists": [
                  {
                     "rows": [
                        {
                           "fields": {
                              "Date": "2020-08-07",
                              "Description":"Writing data to json/text field",
			      "MyMimeColumn":{
                                "Object1Key":"{\"amount\":\"100.00\",\"currency\":\"CHF\"}",
                                "Object2Key":"{\"amount\":\"200.00\",\"currency\":\"EUR\"}"
                              }
                           },
                           "operation": {
                              "name": "add"
                           }
                        }
                     ]
                  }
               ]
            },
            "nameXml": "Transactions"
          }
        ]
      },
      "fileVersion": "1.0.0"
    }
  ]
}

 

Example adding attachments (text/plain) to the table Documents

DocumentChange allows you to insert a text in the Attachments Column available in the Documents table. The MIME type is text/plain and cannot be changed. 

  • The contents of the field must be passed as a string
  • Other types of MIME fields (image, HTML text, Markdown code, CSS stylesheet, Javascript code) are currently not supported.

This property has been introduced in BananaPlus 10.1.20


// Creates a JSON DocumentChange which adds a row with an attachment to the Documents table.
//
// @id = ch.banana.example.documentpatchMime
// @api = 1.0
// @pubdate = 2024-04-17
// @doctype = *.*
// @description = Add attachments to Documents Table
// @task = app.command
// @timeout = -1
function exec() {

var jsonContent = {
    "billing_info": {
        "total_amount_vat_exclusive": "51.00",
        "total_amount_vat_exclusive_before_discount": "51.00"
    }
};

var jsonChange = {
  "format": "documentChange",
  "error": "",
  "data": [
    {
      "document": {
        "dataUnits": [ {
            "nameXml": "Documents",
            "data": {
              "rowLists": [ {
                  "rows": [ {
                    "fields": {
                        "RowId": "MyDocument 1",
                        "Description":"Writing data to the attachmnents field",
                        "Attachments": JSON.stringify(jsonContent, null, 3)
                     },
                     "operation": {
                        "name": "add"
                     } } ]
              } ]
        } } ]
    } } ]
};

return jsonChange;
}

 

Helfen Sie uns, unsere Dokumentation zu verbessern

Ihre Anregungen, wie wir diese Seite verbessern könnten, sind uns jederzeit willkommen.

Sagen Sie uns bitte, welches Thema eine bessere Erklärung braucht oder wie wir ein Argument verständlicher erklären könnten.

Diesen Artikel teilen: Twitter | Facebook | LinkedIn | Email