- Created by Morten Lindequist Køhler, last modified by Thomas Olthuis on Nov 19, 2024
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 2 Current »
Using the Update-statement it is possible to update feature values on items in Perfion. Update works on both selectables and non-selectable features
The below example will set the English value for the selectable feature Color to “Black” for all items that has the feature ItemName set to “1234”.
XML:
<Query> <Update> <Item> <Color language='EN'>Black</Color> </Item> </Update> <From id="Product" /> <Where> <Clause id="ItemName" operator="=" value="1234" /> </Where> </Query>
JSON:
{ "query": { "Update": { "Item": { "Values": [ { "name": "Color", "language": "EN", "value": "Black" }, ] } }, "From": { "id": "Product" }, "Where": { "Clauses": [ { "Clause": { "id": "ItemName", "operator": "=", "value": "1234" } } ] } } }
Since Color is a selectable and “Black” hereby represents an item the same can be achieved by the following update:
XML:
<Query> <Update> <Item> <Color id="347" /> </Item> </Update> … </Query>
JSON:
{ "query": { "Update": { "Item": { "Values": [ { "name": "Color", "id": "347" }, ] } }, … } }
As can be seen it is here the id if the item that is specified instead of the value of it. The result is the same.
The Language-attribute may only be specified for localizable features, and only for selectables if you update them by value rather than by id.
Specifying a value for a selectable only works if the value uniquely defines a single item. If two or more items are named the same, an error will be returned, and nothing will be updated. The same will happen if no item has the specified value.
The base value of an item is updating by using the name value as shown below:
XML:
<Query> <Update> <Item> <Value language='EN'>Some value</Value> </Item> </Update> … </Query>
JSON:
{ "query": { "Update": { "Item": { "Values": [ { "name": "Value", "language": "EN", "value": "Some value" }, ] } }, … } }
Updating Parent Item and Brand
Updating Parent Item and Brand is simply adding the attributes “Brand” and/or ParentID to the <Item>-Element.
XML:
<Query> <Update> <Item brand='Virtual' parentID='4455'> <Color language='EN'>Black</Fuel> </Item> </Update> … </Query>
JSON:
{ "query": { "Update": { "Item": { "brand": "Normal", "parentid": 1234, "Values": [ { "name": "Color", "language": "EN", "value": "Black" }, ] } }, ... } }
Updating multiple features
Updating multiple features simultaneously is simply achieved by specifying multiple features inside the <Item>-Element.
XML:
<Query> <Update> <Item> <Color language='EN'>Black</Fuel> <EAN>4242003651410</EAN> <Category language='DAN'>Kaffe Maskiner</Category> <PowerW>1800</PowerW> </Item> </Update> … </Query>
JSON:
{ "query": { "Update": { "Item": { "Values": [ { "name": "Color", "language": "EN", "value": "Black" }, { "name": "EAN", "value": "4242003651410" }, { "name": "Category", "language": "DAN", "value": "Kaffe Maskiner" }, { "name": "PowerW", "value": "1800" }, ] } }, ... } }
Updating multi-value features
Updating multi-selectable features is achieved by specifying the same feature multiple times. The example below shows exactly this for a selectable multi value. Note that it is allowed to combine assigning values by their id with assigning the values themselves.
XML:
<Query> <Update> <Item> <Catalog id='876' /> <Catalog id='865' /> <Catalog language='EN'>Coffee Maker, Coffee Brewers</Catalog> </Item> </Update> ... </Query>
JSON:
{ "query": { "Update": { "Item": { "Values": [ { "name": "Catalog", "id": "876" }, { "name": "Catalog", "id": "865" }, { "name": "Catalog", "language": "EN", "value": "Coffee Maker, Coffee Brewers" } ] } }, ... } }
Clearing values
Clearing a value is done by setting the feature to nothing instead of specifying a value or Item ID.
XML:
<Query> <Update> <Item> <Color /> </Item> </Update> ... </Query>
JSON:
{ "query": { "Update": { "Item": { "Values": [ { "name": "Color" } ] } }, ... } }
Support for time zone
When updating items based you can choose to update items based on some criteria where you use some timestamp-information. In such cases it might be useful to be able to supply information about the time zone. This has been possible since version 4.7 as the following example demonstrates:
XML:
<Query> <Update timezone="Eastern Standard Time"> <Item> <Color>Blue</Color> </Item> </Update> <From id="Product" /> <Where> <Clause id="ModifiedDate" operator=">=" value="2020-01-17 11:00:00" /> <Clause id="ModifiedDate" operator="<=" value="2020-01-17 12:00:00" /> </Where> </Query>
JSON:
{ "query": { "Update": { "Item": { "Values": [ { "name": "Color", "value": "Blue" }, ] } }, "From": { "id": "Product" }, "Where": { "Clauses": [ { "Clause": { "id": "ModifiedDate", "operator": "BETWEEN", "value": [ "2020-01-17 11:00:00", "2020-01-17 12:00:00" ] } } ] } } }
In the above example all Products modified between 11:00:00 and 12:00:00 (both included) on January 17th, 2020 Eastern Standard Time will have the feature “Color” set to “Blue”. If no time zone is supplied, the above query will use whatever time zone in which the database is running. Before Perfion 4.7 the database time zone where always used.
- No labels