to get a personalized navigation.
to get a personalized navigation.
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
@omelhus This is now deployed to production. Here is an example of how to use it:
mutation insert_order_lines(
$cid : Int!,
$ono : Int,
$seq : Int,
$pno1 : String,
$pno2 : String)
{
useCompany(no : $cid)
{
orderLine_create(
values : [
{
productNo : $pno1,
quantity : 1,
priceInCurrency : 100
},
{
productNo : $pno2,
quantity : 1,
priceInCurrency : 42
}
],
insertAtRow : {_and : [
{ orderNo : {_eq : $ono}}
{ lineNo : {_eq : $seq}}
]},
insertPosition : BEFORE)
{
affectedRows
items
{
orderNo
lineNo
sortSequenceNo
productNo
quantity
priceInCurrency
}
}
}
}
It's documented here https://docs.business.visma.net/docs/schema/mutations/inserts#insert-between-existing-records but works as described above basically.
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:
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.
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.
Enum is the way to go 👍
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) {
}
That would be really good!
Copyright © 2022 Visma.com. All rights reserved.