Bulk-entity form

Some input entities in GOERP may be submitted as a bulk (having multiple records in scope of one form submit), allowing to create or update multiple records at once. Such inputs have array types in data source definition - []string (e.g. ErplyApi.ProductInSupplierPriceList). Also, bulk input fields may be a part of some complex input entities (e.g. ErplyApi.SalesDocumentInput) accepts many Row’s as part of the input.

Warning
  1. Every row in the bulk should always have same order of inputs as others (check samples).
  2. All rows in the bulk should always have same amount of inputs. For example, goerp will fail if one row contains Name and Code and second one have ID, Name and Code. If ID undefined, then pass empty value with an input.

Bulk-entity form sample

<form method="POST">

   {{/* Define entity name that should be processed */}}
   <input type="hidden" name="postActionEntity" value="ProductInSupplierPriceList">

   {{/* Empty row (to add new) */}}
   <fieldset>
      <legend>Create row:</legend>
      <label for="spl-id">Supplier price list ID:</label>
      <input type="text" id="spl-id" 
             name="ErplyApi.ProductInSupplierPriceList.SupplierPriceListID">
      <label for="product-id">Product ID:</label>
      <input type="text" id="product-id" 
             name="ErplyApi.ProductInSupplierPriceList.ProductID">
   </fieldset>

   <h2>Existing rows</h2>
   {{/* Populate existing rows for update */}}
   {{ range $i, $el := .Data.ErplyApi.ProductInSupplierPriceListList }}
   <fieldset>
      <legend>Row {{$i}}:</legend>
      <label for="spl-id-{{$i}}">Supplier price list ID:</label>
      <input type="text" id="spl-id-{{$i}}"
             name="ErplyApi.ProductInSupplierPriceList.SupplierPriceListID"
             value="{{$el.SupplierPriceListID}}">
      <label for="product-id-{{$i}}">Product ID:</label>
      <input type="text" id="product-id-{{$i}}"
             name="ErplyApi.ProductInSupplierPriceList.ProductID"
             value="{{$el.ProductID}}">
   </fieldset>
   {{ end }}
</form>

Subsections of Bulk-entity form

Sales document sample

<!-- Display possible api errors -->
<div>
  {{ range .Data.Errors }}
  <span>{{ . }}</span>
  {{ end }}
</div>

<form method="post">
  <!-- Field used by goErp to state what we want to save -->
  <input type="hidden" name="postActionEntity" value="SalesDocumentInput"/>

  <!-- Need to set the ID of the existing document -->
  <input type="hidden" name="ErplyApi.SalesDocumentInput.ID"
         value="{{ .Data.ErplyApi.SalesDocumentInput.ID }}">

  <table>
    <thead>
    <tr>
      <th>Product ID</th>
      <th>Amount</th>
      <th>Price</th>
    </tr>
    </thead>

    <tbody>
    {{ range $row := .Data.ErplyApi.SalesDocument.Rows }}
    <tr>
      <td>
        <!-- Stable row id is used by erply api to determine existing rows
        the api always replaces all rows so adding a single row means all rows need to be resaved -->
        <input type="hidden" name="ErplyApi.SalesDocumentInput.RowStableRowID"
               value="{{ $row.StableRowID }}">
        <input name="ErplyApi.SalesDocumentInput.RowProductID" value="{{ $row.ProductID }}">
      </td>
      <td><input name="ErplyApi.SalesDocumentInput.RowAmount" value="{{ $row.Amount }}"></td>
      <td><input name="ErplyApi.SalesDocumentInput.RowPrice" value="{{ $row.Price }}"></td>
    </tr>
    {{ end }}
    <tr>
      <td>
        <input type="hidden" name="ErplyApi.SalesDocumentInput.RowStableRowID" value="0">
        <input name="ErplyApi.SalesDocumentInput.RowProductID" value="" placeholder="Product ID">
      </td>
      <td><input name="ErplyApi.SalesDocumentInput.RowAmount" value="0"></td>

      <!-- Manual pricing allowed? -->
      <td><input name="ErplyApi.SalesDocumentInput.RowPrice" value="0"></td>
    </tr>
    </tbody>
  </table>

  <!-- Erply api returns this boolean as a string 0 or 1 for some reason -->
  {{ if eq .Data.ErplyApi.SalesDocument.Confirmed "1" }}
  <h2>Confirmed documents cannot be edited</h2>
  {{ else }}
  <button type="submit">Save</button>
  {{ end }}
</form>