Delete node where attribute = variable - tsql

I am in need of some help - how do I delete a node from an untyped XML Field where the attribute is equal to a sql Variable?
This is what I have tried:
DECLARE #AttributeKey varchar(500) = 'TestColorBox1';
UPDATE
Numbers
SET
AttributeKeyValues.modify('delete (/attributes/attribute[#key="{sql:variable("#AttributeKey")"]}/*')
WHERE
AccountId = 2000046
SELECT * FROM Numbers
ps. Sorry if the question is vague, I literally started with xquery yesterday. I already read up that you define a sql Variable as
"sql:variable("#variableName")"
Error:
Msg 9303, Level 16, State 1, Line 6
XQuery [Numbers.AttributeKeyValues.modify()]: Syntax error near '#', expected ']'.
Update:
Got it to run without errors: still not deleting the node i need to delete
DECLARE #AttributeKey varchar(500) = 'TestColorBox1';
UPDATE
Numbers
SET
AttributeKeyValues.modify('delete (/attributes/attribute[#key="{sql:variable("#AttributeKey")}"])')
WHERE
AccountId = 2000046
SELECT * FROM Numbers
Another Update: XML Used
<attributes>
<attribute key="TestColorBox1">TEST1</attribute> <!-- Targeted Field -->
<attribute key="test2345">TEST2</attribute>
<attribute key="test23454">TEST3</attribute>
<attribute key="test24568798">TEST4</attribute>
<attribute key="TEST123214124124">TEST5</attribute>
</attributes>

Delete the attribute node in attributes where the attribute #key is equal to the value of local variable #AttributeKey
modify('delete /attributes/attribute[#key = sql:variable("#AttributeKey")]')

Related

SAP Flexible Workflow pre-condition value not loaded in edit mode

I've created a new pre-condition field in Workflow Flexible called Transfer Type with default domain values (T/B).
When I save the WF with T or B in this field it's OK, the value is saved.
But when I try to edit this workflow the value is cleared and we need to fill again the Transfer Type.
Question to the experts, how can I recover the value saved before in this field?
Thank you in advance!
In the OData field map:
/sap/opu/odata/sap/ZWF_FI_SEARCH_HELP_CDS/?$format=xml
<app:collection sap:creatable="false" sap:updatable="false" sap:deletable="false"
sap:searchable="true" sap:content-version="1" href="zC_FI_Transfer_Type">
<atom:title type="text">zC_FI_Transfer_Type</atom:title>
<sap:member-title>Check Budget</sap:member-title>
<atom:link href="zC_FI_Transfer_Type/OpenSearchDescription.xml" rel="search"
type="application/opensearchdescription+xml" title="searchzC_FI_Transfer_Type" />
</app:collection>
In SPRO path:

Problem with rule validation - valid on save, invalid on load

While testing the unchanged CodeEffects asp.net core demo application (Editor 5.0.4.8, Engine 5.0.2.6) I've found an interesting problem.
If I create an execution rule that checks for example if FirstName contains two spaces, I can save this rule without a problem, and in SaveRule action it passes the validation using editor.Rule.IsValid. Here is an example of the rule definition:
<if>
<clause>
<condition type="contains" stringComparison="OrdinalIgnoreCase">
<property name="FirstName" />
<value> </value>
</condition>
</clause>
<then>
<method name="Register">
<value>aaaa</value>
</method>
</then>
</if>
But when refreshing the editor and trying to load this saved rule it won't load into editor. The reason is that the LoadRule controller action returns empty json.
While investigating this further it looks that the editor.GetClientRuleData returns null because the rule is invalid. If I check editor.Rule.IsValid just before calling editor.GetClientRuleData I can see it return false and the editor.Rule.InvalidElements holds one element:
{{c:"",h:"v120"}}
The error message would be "The only allowed operators for empty string values are IS and IS NOT" but of course it's not shown in the editor in the demo project as this is not expected to happen.
Not sure if this is in any way related to the problem, but one obvious difference between LoadRule and SaveRule actions is how the rule is loaded.
When saving the rule, the rule data (coming from the UI) is loaded into editor with
editor.LoadClientData(data.Data);
and when loading the rule it's loaded using the xml (from the storage) effectively calling this:
editor.Rule = Rule.Models.RuleModel.Create(ruleXml, typeof(Models.Patient))
So my question is why can invalid rule pass the validation on save, and then the same rule fails the validation on load? Any fix I can try or a workaround?
This issue has been fixed in the latest version of Rule Editor. You need to update Code Effects references from NuGet:
CodeEffects.Rule.Common - 5.0.2.4, CodeEffects.Rule.Editor.Core - 5.0.4.1 (this is the assembly that contains that fix), CodeEffects.Rule.Editor.Web.Core - 5.0.4.8

Edit length of increment_id in sales_order table on Magento 2

I want to decrease length of order increment #00000000001 to #00001.
I found some tutorials for magento 1 but not for Magento 2.
Please help if someone is aware how to perform this task.
Thanks
In the etc directory of your module, add a di.xml file with this content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\SalesSequence\Model\Sequence">
<arguments>
<argument name="pattern" xsi:type="string"><![CDATA[%s%'.05d%s]]></argument>
</arguments>
</type>
</config>
This way Magento will pass a 5 digit pattern instead of its default pattern made by 9 digits.
This is because the first and the last %s symbol are replaced respectively with the prefix and the suffix values stored in the sales_sequence_profile table. The matching is done with the meta_id of your store (you can check yours by reading from the sales_sequence_meta table). The %'.05d pattern means that you want an integer with 5 padding digits on its left which is replaced with the next order number calculated by Magento.
For example, assuming that you have:
Prefix: PX
Suffix: SX
with the above pattern, the first order number will be PX00001SX
you can decrease length of order increment #00000000001 to #00001.
Try this: https://store.emizentech.com/magento2/custom-order-and-invoice-number-magento-2-0.html
Solved with a custom developed plugin:
I already had an observer to save the customer as new customer automatically after placing an order and before rendering the success page:
On the events.xml (already existing observer i've previously made)
<event name="sales_order_place_after">
<observer name="customcheckout_customer" instance="Dufry\CustomCheckout\Model\Observer\SaveCustomer"/>
</event>
On the observer SaveCustomer.php (already existing observer i've previously made):
$order = $observer->getOrder();
$increment = $order->getIncrementId();
if(strlen($increment) > 9){
$newIncrement = substr($increment, -8);
$newIncrement = substr($increment,0,1).$newIncrement;
$order->setIncrementId($newIncrement);
}
...
$order->save()
And worked like a charm.
I did the second "substr" part to keep the prefix the was previously configured.

XSLT - how to put original XML into transformation result in text output mode

i am trying to create a transformation which output will be text but including original xml as well. Simply i got the xml message that should be transformed to SQL insert but in case of an SQL error i want to insert the original xml message to database as well.
The input is e.g.:
<message><tag name="foo">dummy</tag></message>
The result of the transformation should be then:
INSERT INTO table (column) VALUES ('dummy')
IF ##error <> 0
BEGIN
INSERT INTO errMsgLog (message) VALUES ('<message><tag name="foo">dummy</tag></message>')
END
The problem is if i set the output in XSLT to 'text' there are no xml tags included (just the values). So is there any mixed output mode or attribute override?
Thanks for any help.
Before approaching this solution (don't know if through XSLT you can find some better solution), also consider the problems you will encounter with much more complex input and output.
Even if purists will reject this answer (and the question also), you can use "xml" output method to do a (very ugly) trickery:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:text disable-output-escaping="yes">INSERT INTO table (column) VALUES ('dummy')
IF ##error <> 0
BEGIN
INSERT INTO errMsgLog (message) VALUES ('</xsl:text>
<xsl:copy-of select="."/><xsl:text>')
END</xsl:text>
</xsl:template>
</xsl:stylesheet>
outputs:
INSERT INTO table (column) VALUES ('dummy')
IF ##error <> 0
BEGIN
INSERT INTO errMsgLog (message) VALUES ('<message><tag name="foo">dummy</tag></message>')
END
Some processors (e.g. Saxon) have an extension function serialize() which allows you to convert an XML node into a serialised XML representation, which the function returns as a string. You could call this and then output it in your text result. If your processor doesn't have such an extension function, then it might not be difficult to write one.

How to access input control parameters from Jasper server?

I want to create a jasper report which changes the query and add/removes additional conditons in its where clause based on the input provided by the user in the jasper server.
One option is to sql inject the querystring in the jrxml file, but that looks messy as we may have additional conditions in the where clause which may be added.
The other approach mentioned in this post Dynamic querystring in JRXML seems to be a good one.
I would like to know how can I access the control parameters in the java code passed from jasper server?
Or can I give some kind of conditional logic within the jrxml file? which checks if some of the input controls are empty then assign one query in the queryString variable and another query if other conditions are valid?
Thanks.
Buld a "fake" parameter named P_DYNAMIC_WHERE_CLAUSE, based on your real input parameters. For instance:
<parameter name="PARAM1" class="java.lang.Long">
<parameterDescription><![CDATA[Real query criteria on column1]]></parameterDescription>
</parameter>
...
<parameter name="P_WHERE_CLAUSE_PARAM1" class="java.lang.String" isForPrompting="false">
<parameterDescription><![CDATA[Computed parameter, containing the optional SQL where clause corresponding to parameter PARAM1]]></parameterDescription>
<defaultValueExpression><![CDATA[$P{PARAM1} != null ? " $X{EQUAL, COLUMN1, PARAM1} " : " "]]></defaultValueExpression>
</parameter>
and use the $P!{P_DYNAMIC_WHERE_CLAUSE} syntax in the queryString.
For instance:
<queryString>
<![CDATA[SELECT /* my_jasper_report */ column1
FROM my_table
WHERE (1=1)
$P!{P_DYNAMIC_WHERE_CLAUSE}
]]>
</queryString>