I'm trying to modify xml attribute in my table:
XML:
<root>
<object name="111">
<fields>
<field name="1">False</ofield>
<field name="VIN">123</field>
</fields>
</object>
</root>
UPDATE wftable
SET XML.modify('replace value of
(root/object[#name="111"]/fields/field/#name[.="VIN"])[1]
with "testNumber"')
WHERE id = 20889436
But I get as a result
<field name="testNumber">123</field>
Actually I just want to update xml node like this:
<field name="VIN">testNumber</field>
How can I modify my UPDATE query?
You need to specify the text() node of field as the node you want to update.
replace value of
(root/object[#name="111"]/fields/field[#name="VIN"]/text())[1]
with "testNumber"
Related
Unfortunately I can't handle the XPath syntax in the Laout.xml of Speedata .
I've been programming XSL for years and maybe I'm a bit preburdened.
The XML I'm trying to evaluate has the following structure:
<export>
<object>
<fields>
<field key="demo1:DISPLAY_NAME" lang="de_DE" origin="default" ftype="string">Anwendungsbild</field>
<field key="demo1:DISPLAY_NAME" lang="en_UK" origin="inherit" ftype="string">application picture</field>
<field key="demo1:DISPLAY_NAME" lang="es_ES" origin="self" ftype="string">imagen de aplicación</field>
</fields>
</object>
</export>
The attempt to output the element node with the following XPath fails.
export/object/fields/field[#key='demo1:DISPLAY_NAME' and #lang='de_DE' and #origin='default']
How do I formulate the query in Speedata Publisher, please?
Thnk you for our Help.
The speedata software only supports a small subset of XPath. You have two options
preprocess the data with the provided Saxon XSLT processor
iterate through the data yourself:
<Layout xmlns="urn:speedata.de:2009/publisher/en"
xmlns:sd="urn:speedata:2009/publisher/functions/en">
<Record element="export">
<ForAll select="object/fields/field">
<Switch>
<Case test="#key='demo1:DISPLAY_NAME' and #lang='de_DE' and #origin='default'">
<SetVariable variable="whatever" select="."/>
</Case>
</Switch>
</ForAll>
<Message select="$whatever"></Message>
</Record>
</Layout>
(given your input file as data.xml)
Today I tried to import some configuration from one data base of Odoo to another (User-defined Defaults) and everything looks ok, but the default values that i'm trying to insert to my new data base (for many2many fields) don't work. I believed it was by for the csv file and i try to add using xml record like this:
<record id="hr_test_record" model="ir.values">
<field name="value_unpickle">2</field>
<field name="name">struct_id</field>
<field name="model">hr.contract</field>
<field name="key">default</field>
<field name="value">I2 .</field>
</record>
but in the database space (for value) appears this way after install the module
value
S'2' +
p0 +
.
And has to look like this
value
I2 +
.
I know this but how can apply this?
I is for Integer
S is for string
V is for value
To store the value as integer, you must use XML notation to encode the \n character (result of pickle.dumps operation) and must not specify a value for the field "value_unpickle".
e.g.
<record id="hr_test_record" model="ir.values">
<field name="name">struct_id</field>
<field name="model">hr.contract</field>
<field name="key">default</field>
<field name="key2"/>
<field name="value">I2
.</field>
</record>
note that you also need to set key2 to empty string if you don't want any conditions/qualifiers for your default value.
(the above is tested in odoo 10)
I have the following XML data stored in a SQL table
<CustomFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.kaseya.com/vsa/2007/12/ServiceDeskDefinition.xsd">
<Field fieldName="ChangeRequest">No</Field>
<Field fieldName="ProblemRecord">No</Field>
<Field fieldName="Source">Email</Field>
<Field fieldName="KB_Article">No</Field>
<Field fieldName="OptimusRef">264692</Field>
<Field fieldName="TimeSpentOnTicket">0.25</Field>
<Field fieldName="PONumber" />
<Field fieldName="ResourceAssignedEngineer" />
What I would like to do is select the TimeSpentOnTicket Value form a stored procedure.
Any ideas how I can do this?
The problem here is your XML. It's invalid, so there's not really a way do search it until you fix it. A simple way to check this is using an online tool like the one at W3Schools. Another issue that I see is that the namespace (xmlns) that you reference no longer exists. I think this will mess up Postgres as well, but I'm not 100% on that. You might to have to filter that out when ingesting. However, after fixing the XML, it's pretty easy to get things out using XPath within the appropriate XML function.
For example, using the following table:
CREATE TABLE BLA.TEMPTABLE (ID INT, MYXML XML)
Then, insert a valid version of your XML:
INSERT INTO BLA.TEMPTABLE ( ID, MYXML )
SELECT 1 as ID,
'<?xml version="1.0" encoding="UTF-8"?>
<CustomFields>
<Field fieldName="ChangeRequest">No</Field>
<Field fieldName="ProblemRecord">No</Field>
<Field fieldName="Source">Email</Field>
<Field fieldName="KB_Article">No</Field>
<Field fieldName="OptimusRef">264692</Field>
<Field fieldName="TimeSpentOnTicket">0.25</Field>
<Field fieldName="PONumber" />
<Field fieldName="ResourceAssignedEngineer" />
</CustomFields>' as MYXML
Then, to query it back out, you can do something like the following (you can test your XPath with a tool like this, if you need to):
SELECT
tt.ID,
tt.MYXML,
XPATH('/CustomFields//Field[#fieldName=''TimeSpentOnTicket'']/text()', tt.MYXML)
FROM
BLA.TEMPTABLE tt
I am trying to set default account for some fields for that i write some code like
<!-- 1.Income account–311000 -->
<record forcecreate="True" id="property_account_income_product" model="ir.property">
<field name="name">property_account_income</field>
<field name="fields_id" search="[('model','=','product.template'),('name','=','property_account_income')]"/>
<field eval="'account.account,'+str(account_account_456)" name="value"/>
<field name="company_id" ref="base.main_company"/>
</record>
in account.account.template i write code like
<record model="account.account.template" id="account_account_456">
<field name="name">INCOME FROM SALES</field>
<field name="code">311000</field>
<field name="type">other</field>
<field name="user_type" ref="account.data_account_type_income"/>
<field name="reconcile" eval="False"/>
<field name="parent_id" ref="account_account_256"/>
</record>
but after update database it sets different account
i don't know why but correct account are not set
pleas help me
thanks...
Now i got exact Problem Firstly i put record in account.account.template this record is also automatically added into account.account and when i am trying to add record into ir.property search that Account into account.account.template take id and display record from account.account
so the problem is id mismatch in account.account and account.account.template
how to resolve this problem and sorry for English
This is because you must having multiple entries in model="ir.property" for field property_account_income_product for your company so when you try an see the values for the a/c you will find the first value get set on field as your record may be second in list, so it get not selected.
I am creating an application that parses an XML and retrieves some data. Each xml node specifies the data (const), a recordset's column-name to get the data from (var), a subset of possible data values depending on some condition (enum) and others. It may also specify, alongside the data, the format in which the data must be shown to the user.
The thing is that for each node type I need to process the values differently and perform some actinons so, for each node, I need to store the return value in a temp variable in order to later format it... I know I could format it right there and return it but that would mean to repeat myself and I hate doing so.
So, the question: How can I store the value to return, in a temp variable, while avoiding boxing/unboxing when the type is unknown and I can't use generics?
P.S.: I'm designing the parser, the XML Schema and the view that will fill the recordset so changes to all are plausible.
Update
I cannot post the code nor the XML values but this is the XML structure and actual tags.
<?xml version='1.0' encoding='utf-8'?>
<root>
<entity>
<header>
<field type="const">C1</field>
<field type="const">C2</field>
<field type="count" />
<field type="sum" precision="2">some_recordset_field</field>
<field type="const">C3</field>
<field type="const">C4</field>
<field type="const">C5</field>
</header>
<detail>
<field type="enum" fieldName="some_recordset_field">
<match value="0">M1</match>
<match value="1">M2</match>
</field>
<field type="const">C6</field>
<field type="const">C7</field>
<field type="const">C8</field>
<field type="var" format="0000000000">some_recordset_field</field>
<field type="var" format="MMddyyyy">some_recordset_field</field>
<field type="var" format="0000000000" precision="2">some_recordset_field</field>
<field type="var" format="0000000000">some_recordset_field</field>
<field type="enum" fieldName ="some_recordset_field">
<match value="0">M3</match>
<match value="1">M4</match>
</field>
<field type="const">C9</field>
</detail>
</entity>
</root>
Have you tried using the var type? That way you don't need to know the type of each node. Also, some small sample of your scenario would be useful.