Upland OL User community

Help with unique values from XML

Good day to all
We currently have a system that generates approximately 65,000 invoices daily and requires control of your distribution and messaging service, so we want you to add an additional page from the design that is printed when a node “A” changes its value and generates a small summary table with the unique values of a “B” node and its quantities, in order to leave with the same invoices at the end of each cycle.
The fact that the page is generated when the value of the “A” node is changed, it was not complicated was achieved with a conditional applied to when this node changes value, but creating the summary “table” we have not achieved with the Talk I managed to generate the list of values, but not the only ones and less that the count only lists them with this small line of code.
define(&i, integer, 0)
define(&neighborhood, string, ‘’)
define(&numberOfItems, integer, xmlcount(’/GENERAL/DATA_SET’))
for(&i, 1, 1, &numberOfItems)
&neighborhood := xmlget(’/GENERAL/DATA_SET[’+inttostr(&i)+’]/DIRECCION_SERVICIO/NEIGHBORHOOD’)
The old forum I see that they talk about using scripts this version as it uses them and if possible, from the design, I do not see references to do it with XML and additional this does not use UTF-8 uses encoding=“iso-8859-15”

Good evening, I managed to somehow read the XML with a script from the flow and pass it to the designer, but it does not bring me in columns and it brings me everything in a single line from the designer, I bring the variable like this:
define(&result, string, ‘’)
&result := ExpandString(’%{global.csvContent}’)

and the script in the flow is the following:

’ Create FileSystemObject object
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

’ XML file path
strFile = Watch.GetJobFileName
’ Check if the file exists

'If Not objFSO.FileExists(strFile) Then
'MsgBox(“The file does not exist.”)
’ WScript.Quit
'End If

’ Create XML DOM object
Set xmlDoc = CreateObject(“Microsoft.XMLDOM”)

’ Load XML file
xmlDoc.setProperty “SelectionLanguage”, “XPath”
xmlDoc.async = False
xmlDoc.load strFile

’ Check for errors in loading the XML file
If xmlDoc.parseError.errorCode <> 0 Then
MsgBox("Error loading XML file: "& xmlDoc.parseError.reason)
’ The XML file has been loaded successfully

 ' Create FileSystemObject for the CSV file
 Set objCSV = objFSO.CreateTextFile("C:\CarpetasPlanet\Temp\neighborhoods.csv", True)

 ' Write headers to CSV file
 objCSV.Write "Neighborhood, Amount of Invoices" & vbCrLf

 ' Create a Dictionary object to store the unique values and their number of occurrences
 Set uniqueValues = CreateObject("Scripting.Dictionary")

 ' Select all "data_set" nodes
 Set xmlNodeList = xmlDoc.documentElement.selectNodes("/*/*/SERVICE_ADDRESS")

 ' Loop through all "data_set" nodes
 For Each xmlNode In xmlNodeList
     ' Get the value of the "neighborhood" node
     value = xmlNode.SelectSingleNode("NEIGHBORHOOD").Text

     ' If the value is already in the Dictionary, increase its amount by 1
     If uniqueValues.Exists(value) Then
         uniqueValues(value) = uniqueValues(value) + 1
     ' If the value is not in the Dictionary, add it and set its amount to 1
         uniqueValues(value) = 1
     End If

 ' Loop through the Dictionary and write each unique value and its quantity to the CSV file
 For Each key In uniqueValues.Keys
     objCSV.Write key & "," & uniqueValues(key) & vbCrLf

 ' Close the CSV file

 ' Read the content of the CSV file into a variable
 Set objFile = objFSO.OpenTextFile("C:\CarpetasPlanet\Tem\neighborhoods.csv")
 'csvContent = objFile.ReadAll
 Dim csvRows
 csvRows = Split(objFile.ReadAll, vbCrLf) ' Split by rows

 ' Convert the list of rows to a string with newlines
   csvContent = Join(csvRows, vbCrLf)

 'send the data to the variable to take it in planet
 'dim Watch
 'set Watch = CreateObject("MSEnterpriseLibrary.Watch")
 Watch.SetVariable "global.csvContent", csvContent

 ' Indicate that the task has been completed

 'MsgBox("Process completed successfully.")

End If
Yes, I have a lot in the comments of so many tests, but if that is omitted, everything “works”

Good night
I have new advances with the following script I managed to get the unique and pass them through variables to the designer

Dim fso, ts, xmlDoc, xmlPart, itineraries, neighborhoods
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set ts = fso. OpenTextFile(Watch.GetJobFileName)
Set xmlDoc = CreateObject(“Microsoft.XMLDOM”)

xmlDoc.async = False
xmlDoc.setProperty “SelectionLanguage”, “XPath”

Set itineraries = CreateObject(“Scripting.Dictionary”)
Set neighborhoods = CreateObject(“Scripting.Dictionary”)

While Not ts. AtEndOfStream
xmlPart = ts. Read(1024*1024)’ Read the file in 1MB blocks

' concatenate the read block to the xml document
If Not xmlDoc.loadXML(xmlPart) Then
    WScript.Echo "Error loading XML:" & xmlDoc.parseError.reason
End If

’ Process the nodes DIRECCION_SERVICIO in the current block
For Each address In xmlDoc.SelectNodes("///DIRECCION_SERVICIO")
itinerary = direction. SelectSingleNode(“ITINERARY_ID”). Text
neighborhood = address. SelectSingleNode(“NEIGHBORHOOD”). Text

    ' Increase the neighborhood counter for the current itinerary
    If neighborhoods. Exists(itinerary & "|" & neighborhood) Then
        neighborhoods(itinerary & "|" & neighborhood) = neighborhoods(itinerary & "|" & neighborhood) + 1
        neighborhoods(itinerary & "|" & neighborhood) = 1
    End If

    ' Update the current itinerary if it is different from the previous one
    If Not itineraries. Exists(itinerary) Then
        Itineraries(itinerary) = neighborhood
    End If


Ts. Close

’ Print the itineraries and the unique neighborhood corresponding to each one
Dim itineraryText, neighborhoodText
itineraryText = “”
neighborhoodText = “”
For Each itinerary In itineraries. Keys
itineraryText = itineraryText & itinerary & “,”

’ Print the neighborhoods and the corresponding quantity for each itinerary
For Each neighborhood In barrios. Keys
itinerary = Split(neighborhood, “|”) (0)
neighborhoodText = neighborhoodText & "Itinerary: " & itinerary & " Neighborhood: " & Split(neighborhood, “|”) (1) & " Quantity: " & neighborhoods & “,”

’ display the results in the msgbox
'MsgBox itineraryText&neighborhoodText&","

'Watch.SetVariable “global.itinerary”, itineraryText
Watch.SetVariable “global.barrio”, neighborhoodText

As a result I get this when printing (production debug)

In theory we would have to obtain two sheets one with title 1101/116003/1160030040 with the information of line 1 and another with the info of lines 2 and 3 with titles 1101/116003/1160030030.
We have not yet found a way from the designer (pressTalk) to bring us only the info that corresponds to it or from the script we design allows us to only pass the required info when the page asks for it in the print flow.
Someone has managed to make this separate the string that brings the hyphen according to the value of a drop tag
To get me not to print everything on a single line in the talk before adding the following
define(&result, string, ‘’)
&result:= ExpandString(’%{global.barrio}’)
show(&result+‘here neighborhood’)
But I have not managed to get him to show me only the information subject to the ITINERARIO_ID

Hi Hevermondragon,

Your requirements seem to be a little too complex for discussing over a forum like this (as evidenced by the lack of response since your first post). I would advise you to get in touch with our Support team or to contact your reseller to find out how to get a quote from our Services team.