My Products
Help
omelhus
PARTNER

Setting sortSequenceNo on orderLine

by omelhus

Hey,

 

In the UI I have the option to "insert line above" in the order line view.  This will insert a line with an incremented lineNo, but a sortSequenceNo making it go to the line above.

 

Would it be possible to open up for this in the API as well?

 

Cheers

6 REPLIES 6

by Marius Bancila

For this feature, we need to provide a better way to find the place where the new rows are to be inserted. So instead of providing a number as mentioned above, we would provide a filter. The schema is exactly as for the filter argument in read/update/delete operations. However, I suggest we call it differently, such as "insertAtRow". Here is an example of inserting a new line after the 2nd line (in sort order) for the order with number 123:

 

mutation insert_line($cid : Int!)
{
  useCompany(no : $cid)
  {
    orderLine_create(
      values : [{
      	productNo : "uno",
        quantity : 1,
        priceInCurrency : 100
      }],
      insertAtRow : {_and : [
        { orderNo : {_eq : 123}}
        { sortSequenceNo : {_eq : 2}}        
      ]},
      insertPosition : AFTER)
    {
      affectedRows
      items
      {
        orderNo
        lineNo
        sortSequenceNo
        productNo
        quantity
        priceInCurrency
      }
    }
  }
}

You can also specify whether the insertion should occur before or after. Here there are two choices:

  • have an argument like I suggest of an enum type with the values BEFORE and AFTER, which should be mandatory
  • have an optional Boolean argument "insertAfter" that indicates whether the insertion occurs after the identified row; the default, if missing, could be true, so you only need to specify it with the value false if you want inserting before.

If the filter matches multiple lines, the insertion occurs after/before the first result row.

Ideally, the filter should contain the primary key to ensure you identify the right position, but it actually can contain anything that will match the desired row for insert position.

 

Also notice that when inserting like this, the primary key should not be specified in the "values" objects. This is because the primary key is automatically populated when inserting between existing rows. If you do specify it, an error will occur.

 

omelhus
PARTNER

by omelhus

Magnificent!

by Marius Bancila

Just to clarify one thing, about specifying insert position/direction: we won't have both the option of a boolean and an enum. Those two are possible options for designing these schema changes. I tend to opt for the enum (even making it optional) but any feedback here is welcomed.

omelhus
PARTNER

by omelhus

Enum is the way to go 👍

by Marius Bancila

It is possible that we do that. Is there a specific shape of the request that you're thinking of? Like an extra argument, for instance

oderLine_create(values : [{...}], insertAfter : 1) {
} 

 

omelhus
PARTNER

by omelhus

That would be really good!