DOM + need to remove element from XML bt VB script - dom

I have the following VB script , I want to remove the "NET2 ID" element from name list
how to remove the NET2 ID element , need first to verify if NET2 defined and then to delete it
THX
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("\\dir\d.xml")
Set objRoot = objXMLDoc.documentElement
Set objExNode = objRoot.removeChild(objRoot.childNodes.item(1))
the XML file:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<root version="3.0">
<names>
<NET1 ID="10.10.10.1-10" />
<NET2 ID="10.10.10.1-10" />
</names>
</root>

You can use XPath to determine if the node exists then remove it. Something like this:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("\\dir\d.xml")
Set objRoot = objXMLDoc.documentElement
If Not objRoot.selectSingleNode("./names/NET2") Is Nothing Then
Set objExNode = objRoot.firstChild.removeChild(objRoot.firstChild.childNodes(1))
End If
Also, the element NET2 is a child of "names" and not "root", which is the documentElement, so
Set objExNode = objRoot.removeChild(objRoot.childNodes.item(1))
becomes
Set objExNode = objRoot.firstChild.removeChild(objRoot.firstChild.childNodes(1))
EDIT: To add a new node you would do the following. 1 means NODE_ELEMENT
Set newNode = objXMLDoc.createNode(1, "NET3", "")
Set id = objXMLDoc.createAttribute("ID")
id.Value = "newIDValue"
newNode.attributes.setNamedItem(id)
objRoot.firstChild.appendChild(newNode)

Related

Hybris custom Category itemtype not syncing

I've created my own Itemtype extending Category:
<itemtype code="BrandCategory" extends="Category">
<attributes>
<attribute qualifier="hide" type="java.lang.Boolean">
<persistence type="property"/>
<defaultvalue>java.lang.Boolean.FALSE</defaultvalue>
<modifiers read="true" write="true" optional="false" search="true"/>
</attribute>
</attributes>
</itemtype>
However, when I assign this category to any Product that already has other categories and I do a catalog synchronization, all the categories do copy to online except the custom ones (BrandCategory).
How can I fix this bug?
you need to update SyncAttributeDescriptorConfig and it can be done either via Backoffice or via Impex.
"#%groovy%
def query = '''SELECT {pk} FROM {<CustomJOBName>CatalogVersionSyncJob}'''
def syncJobs = flexibleSearchService.search(query).result
//forcing all sync jobs to create sync descriptors, if not created
syncJobs.each { syncJob -> syncJob.getSyncAttributeConfigurations() }
"
UPDATE GenericItem[processor = de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor]; pk[unique = true]
$attribute = attributeDescriptor(enclosingType(code), qualifier)[unique = true]
UPDATE SyncAttributeDescriptorConfig[batchmode = true]; $attribute ; includedInSync
; BrandCategory:hide ; true
UPDATE AttributeDescriptor; enclosingType(code)[unique = true]; qualifier[unique = true]; unique
; BrandCategory ; catalogVersion ; true
To run groovy in Impex, please add this property to local. properties.
Disable legacy scripting (makes groovy work at impex)
impex.legacy.scripting=false
or run impex via enabling the code execution.
Try adding the new type(i.e BrandCategory) into your product synchronization job as a root type as depicted in below image:

How to remove nested element from xml file

I need help removing removing multiple element with the same name and also remove multiple element with the same name with nested element
$file = [xml]#'
<?xml version="1.0"?>
<data>
<title>Name</title>
<date>2019 Jan 01</date>
<actor>
<name>Actor Name 1</name>
<type>Actor</type>
<thumb>image.jpg</thumb>
</actor>
<actor>
<name>Actor Name 2</name>
<type>Actor</type>
<thumb>image.jpg</thumb>
</actor>
<genre>genre1</genre>
<genre>genre2</genre>
</data>
'#
I want to remove acotr element and genre element from the xml
I try following but it didnt work.
foreach($actor in $file.data.actor)
{
$actor.RemoveAll()
}
cls
$file.SelectNodes("//actor") | foreach
{
$file.ParentNode.RemoveChild($_)
}
When the node is a complex type (it has sub elements or attributes), then you can use the following because PowerShell maps this to the node:
$file.data.actor| % { $_.ParentNode.RemoveChild($_) | OUT-NULL }
However, this won't work for things like genre because PowerShell maps it as a string. Instead you can use the following (which will work in either case):
$file.data.SelectNodes('genre') | % { $_.ParentNode.RemoveChild($_) }

Mirth Add Segment HL7 V3

I am new to Mirth/JavaScript. I have a project where I need to add a segment to an incoming HL7 v3 XML file. I have tried the following JavaScript in the destination transformer;
tmp = msg.copy();
tmp.createSegment('templateId', ClinicalDocument, 1);
tmp.ClinicalDocument['templateId'][1]['#root'] ="2.16.840.1.113883.10.20.22.1.1";
This generates an error.
Also I need to place this new segment before the existing templateID segment.
Currently this is what we receive –
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sdtc="urn:hl7-org:sdtc">
<realmCode code="US" />
<typeId root="2.16.840.1.113883.1.3" extension="POCD_HD000040" /><br/>
<templateId root="2.16.840.1.113883.10.20.22.1.2" extension="2015-08-01" />
We want to add
Tranformed Output Desired -
Any help on how to accomplish this will be greatly appreciated.
Thank You
I understand your requirement in this way. That you need to add
<templateId root="2.16.840.1.113883.10.20.22.1.1" extension="2015-08-01" />
Exactly before the templateID
<templateId root="2.16.840.1.113883.10.20.22.1.2" extension="2015-08-01" />
If that's the requirement, this JAVA code will work
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, TransformerException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
// Source XML
File fXmlFile = new File("C:\\Labs\\POC\\Import_Export\\TEST.xml");
Document doc = dBuilder.parse(fXmlFile);
// Get the element after which template ID code has to be added
Node nodeName = doc.getElementsByTagName("typeId").item(0);
// Code to add new Template ID
Element newTemplateID = doc.createElement("templateId");
newTemplateID.setAttribute("root", "2.16.840.1.113883.10.20.22.1.1");
newTemplateID.setAttribute("extension", "2015-08-01");
// Inserting exactly on specific area
nodeName.getParentNode().insertBefore(newTemplateID, nodeName.getNextSibling());
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
// destination XML
StreamResult result = new StreamResult(new File("C:\\Labs\\POC\\Import_Export\\TESTNew.xml"));
transformer.transform(source, result);
}
you will get an XML like this
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sdtc="urn:hl7-org:sdtc">
<realmCode code="US"/>
<typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/>
<templateId extension="2015-08-01" root="2.16.840.1.113883.10.20.22.1.1"/>
<templateId extension="2015-08-01" root="2.16.840.1.113883.10.20.22.1.2"/>
</ClinicalDocument>
Refactor the above code for Mirth specification u will get same output, else u simply want to add extra tags on the end of xml you can use this code in Mirth script
var addTemplateId = new XML("<templateId></templateId>");
addTemplateId['#root'] = '2.16.840.1.113883.10.20.22.1.1';
addTemplateId['#extension'] = '2015-08-01';
var newValue = msg.appendChild(addTemplateId);
msg = newValue;
This will add new tags at the end of the existing tags of the message. which means your output will be like this
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sdtc="urn:hl7-org:sdtc">
<realmCode code="US"/>
<typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/>
<templateId extension="2015-08-01" root="2.16.840.1.113883.10.20.22.1.2"/>
<templateId extension="2015-08-01" root="2.16.840.1.113883.10.20.22.1.1"/>
</ClinicalDocument>

ItemConsolidatedQuery Find by Custom Field

In QuickBooks Desktop, I have an inventory item with a custom field called code. The value of the code is 12345. I need to pull a inventory item where the custom field code is 12345.
Here is my XML:
<?xml version="1.0" encoding="utf-8"?><ItemConsolidatedQuery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.intuit.com/sb/cdm/v2"><CustomFieldEnable>true</CustomFieldEnable><NameContains>temple</NameContains></ItemConsolidatedQuery>
I know the item's name, so I tried to query by it. There are 3 items with the same name, so I attempted to query them later. I am unable to see any custom field data:
http://pastebin.com/FBD1na0s
I know that the custom field exists. Here is my C# code:
Intuit.Ipp.Data.Qbd.ItemConsolidatedQuery itQuery = new Intuit.Ipp.Data.Qbd.ItemConsolidatedQuery();
itQuery.NameContains = "temple";
itQuery.CustomFieldEnable = true;
itQuery.CustomFieldEnableSpecified = true;
itQuery.CustomFieldFilter = Intuit.Ipp.Data.Qbd.customFieldFilterEnumType.Include;
var itemsList = itQuery.ExecuteQuery<Intuit.Ipp.Data.Qbd.ItemConsolidated>(ds.ServiceContext);
Is there a C# example to query custom fields in QBD?
Have you tried adding this line:
itQuery.CustomFieldFilterSpecified = true;
Also, custom fields in QB are secured by OwnerID. Probably theOwnerID must be specified in itQuery.CustomFieldQueryParam; I haven't experimented with it yet.
Need to include OwnerIDList in the request. See the OSR for examples.

How to declare dynamic form field defaults inside a Coldfusion CFC?

I'm looking for a way to declare form default values dynamically in a CFC, I'm calling via AJAX. The current CFC sends orders, which I need to break down into sub-orders.
I had been using this:
<!--- static defaults --->
<cffunction name="Defaults" access="public" returntype="struct" output="false"
hint="Assign default values to instance">
<cfscript>
var formDefaults = {
versenden=""
, speichern=""
...
}
</cfscript>
<cfreturn formDefaults />
</cffunction>
<cffunction name="Commit" access="public" returntype="struct" output="false" hint="database handler">
<!--- add dynamic form fields --->
<cfscript>
var LOCAL = {};
variables.defs = THIS.Defaults();
</cfscript>
<cfloop collection="#VARIABLES.Instance.FormData#" item="formField">
<cfscript>
if ( LEFT(formField, 5) EQ "MENGE"
OR LEFT(formField, 3) EQ "EAN"
OR LEFT(formField, 12) EQ "BESTELL_TEXT"
OR LEFT(formField, 10) EQ "BESTELLTYP"
...
) {
variables.defs[formField]="";
}
</cfscript>
</cfloop>
<cfscript>
structAppend(variables.defs, VARIABLES.Instance.FormData);
LOCAL.Basket = variables.defs;
</cfscript>
...
So I first declare static form fields (single instance only) and then try to dynamically append dynamic form fields to my array, which might be transferred multiple times (MENGE38, MENGE39, MENGE40 etc)
While this works ok, I need to add another counting element to my form-names, so I would have to change MENGE to something like counter.MENGE or MENGE.counter which will then send form values like this:
MENGE.1.38
MENGE.1.40
MENGE.1.41
MENGE.2.37
With the counter denoting the sub-order, this field is used for.
Problem is, this breaks my dynamic form field declaration and I don't understand why. I'm getting the following errors:
Diagnose: Element MENGE.1 is undefined in a CFML structure referenced as part of an expression.
Question:
Can anyone give me a hint on what the problem might be? Do I have to param the form fields on the HTML page as well (shouldn't have to)?
Thanks!
EDIT:
Problem was in my validate function, I also need to declare the modifications I did above. The new function looks like this:
<cffunction name="Validate" access="public" returntype="array" output="false" hint="validate form inputs and return an array of faulty field names.">
<cfscript>
var LOCAL = {};
var double = structNew();
double.form = VARIABLES.Instance.FormData;
double.criteria = VARIABLES.Instance.Validation;
</cfscript>
<!--- add dynamic form fields for validation... I FORGOT TO UPDATE THIS--->
<cfloop collection="#VARIABLES.Instance.FormData#" item="formField">
<cfscript>
if ( LEFT(formField, 5) EQ "MENGE"
OR LEFT(formField, 10) EQ 'BESTELLTYP'
OR LEFT(formField, 3) EQ "EAN"
OR LEFT(formField, 12) EQ "BESTELL_TEXT"
...
) {
VARIABLES.Instance.Validation[formField]="pass";
}
</cfscript>
</cfloop>
<!--- Get error names and type --->
<cfinvoke component="form_validate" method="validate_fields" double="#double#" returnvariable="validation_errors"></cfinvoke>
<cfset LOCAL.ErrorMessages = validation_errors />
<cfreturn LOCAL.ErrorMessages />
Because I did not add the new updated the if-clause in this function, I was getting the error.
To build on Dan Bracuk's answer, use underscores (though you'd need to change the name of "BESTELL_TEXT"). Use this with a combination of listFirst, listGetAt, and listLast to determine field name structure, using underscore as delimiter. Note how I cleaned up your big IF a bit using list function. This code as written probably doesn't do what you need, but wanted to illustrate the concepts without having to understand your business need.
<cfscript>
var orders=structNew();
item=listFirst(formField,'_');
orderNames = "MENGE,EAN,BESTELLTEXT,BESTELLTYPE";
if (listFindNoCase(orderNames,item,'_')){
if (!structKeyExists(orders,item)){
// initialize item
orders[item]=structNew();
}
orderID="";
subOrderId="";
if (listLen(formField,'_') gt 1) {
orderID=listGetAt(formField,2,'_');
}
if (listLen(formField,'_') eq 2) {
orders[item][orderId]=formData[formField];
}
if (listLen(formField,'_') eq 3) {
subOrderId=listLast(formField,'_');
orders[item][orderId][subOrderId]=formData[formField];
}
}
</cfscript>