VBscript variable to income job

Post Reply
joaodaffonsojr
Member
Posts: 23
Joined: Wed Sep 08, 2021 4:36 pm

VBscript variable to income job

Post by joaodaffonsojr »

Hello !

I received a VBscript and I need to make it read the file that are coming from the flow and them export the resultant files to the flow also.
The script is written with fixed folders for incoming and outcoming files.
How can I change that with Switch variables to make this work ?

Code: Select all

' Is invoked each time a new job arrives in one of the input folders for the flow element.
' The newly arrived job is passed as the second parameter.

Function jobArrived(s, job)

'Abrir XML e gerar outro a partir deste
'Cada Row será um XML. Nome dos XMLS é CNPOARQOS & "_" & sequencial
'---------------------------------

Dim i, strNomeXMLSaida, strXMLEntrada, strLocalXMLSaida, strXML

'*************************** PARAMETRIZAR *************************** 
strXMLEntrada = "D:\TRABALHOS\Piffer Print\OS_XML_IN_OUT\ENTRA_1XML_OS\OS_25102_dados_ecalc.xml"
strLocalXMLSaida = "D:\TRABALHOS\Piffer Print\OS_XML_IN_OUT\SAI_XMLS_OS"
'********************************************************************
The strXMLEntrada is the incoming folder that XML arrives
and strLocalXMLSaida is the output folder that the result of script will send the files

I appreciate any help!
bsbertolani
Newbie
Posts: 4
Joined: Thu May 19, 2022 10:08 am
Location: Germany
Contact:

Re: VBscript variable to income job

Post by bsbertolani »

Can you elaborate on the question? For me, it's not clear what should be the result files. Place the example XML file.
But you can read about XML Module This allow you read the nodes of xml.
joaodaffonsojr
Member
Posts: 23
Joined: Wed Sep 08, 2021 4:36 pm

Re: VBscript variable to income job

Post by joaodaffonsojr »

bsbertolani wrote: Fri Jun 10, 2022 4:50 pm Can you elaborate on the question? For me, it's not clear what should be the result files. Place the example XML file.
But you can read about XML Module This allow you read the nodes of xml.
Hello !
Sorry for the poorly worded question, I'll explain better.

I received a VBscript from a client where he needs to split one XML file that has one or more itens (paper types).
The script is written to select the XML in a fixed folder and fixed filename (D:\Enfocus\XML_Split\in\OS_25102_dados_ecalc.xml)
them will split in as many XML´s as there are different itens on it, in the test XML there are 2 only, and the output XML´s
are D:\Enfocus\XML_Split\out\25102_1.xml and D:\Enfocus\XML_Split\out\25102_2.xml.

What I need is that the script gets the file from the flow and not a fixed folder and execute the script and outcome the news XMl´s in the flow, but this could be a fixed folder no problem.
I´m new to scripting and I don´t know if there is a variable in Switch Scripter that can handle this in VBScript.

This is the script:

' Is invoked each time a new job arrives in one of the input folders for the flow element.
' The newly arrived job is passed as the second parameter.

Function jobArrived(s, job)

'Abrir XML e gerar outro a partir deste
'Cada Row será um XML. Nome dos XMLS é CNPOARQOS & "_" & sequencial
'---------------------------------

Dim i, strNomeXMLSaida, strXMLEntrada, strLocalXMLSaida, strXML , nometrab


'*************************** PARAMETRIZAR ***************************
strXMLEntrada = "D:\Enfocus\XML_Split\in\OS_25102_dados_ecalc.xml"
strLocalXMLSaida = "D:\Enfocus\XML_Split\out"
'********************************************************************

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load(strXMLEntrada)
Set colNodes = xmlDoc.selectNodes("//Column")

i=1
iArq = 1
For Each objNode in colNodes 'Caminha em cada Column dos nós Row e a variável i controla cada Column
If i = 1 Then 'Coluna CNPOARQOS do XML
strXML = ""
strNomeXMLSaida = objNode.text & "_" & iArq & ".xml" 'Nome do Arquivo padrão: CNPOARQOS & "_" & iArq
iArq = iArq + 1
End If

strXML = strXML& objNode.xml

If i = 22 Then 'Coluna QTDE_TOTAL do XML, última da Row. Zera i para iniciar na primeira coluna da próxima Row e gera arquivo
Set xmlDocSaida = CreateObject("Microsoft.XMLDOM")
xmlDocSaida.loadXML("<Row>" & strXML & "</Row>")
xmlDocSaida.save strLocalXMLSaida & "\" & strNomeXMLSaida
Set xmlDocSaida = Nothing
i = 0 'Inicia o novo nó
End If

i = i + 1
Next

Set xmlDoc = Nothing


job.sendToSingle job.getPath()

End Function


' Is invoked at regular intervals regardless of whether a new job arrived or not.
' The interval can be modified with s.setTimerInterval().
' Function timerFired(s)

' End Function


' Is invoked each time a new webhook request arrives, if the entry point has subscribed to the request.
' The newly arrived request is passed as the second parameter.
' Function webhookTriggered(s, r)

' End Function
Thanks in advance.
Attachments
sample files.zip
(2.25 KiB) Downloaded 209 times
bsbertolani
Newbie
Posts: 4
Joined: Thu May 19, 2022 10:08 am
Location: Germany
Contact:

Re: VBscript variable to income job

Post by bsbertolani »

If it is your first experience with code, I advise you to read the documentation, and the best option would be to use something ready-made, I found this on the AppStore, this https://www.enfocus.com/en/appstore/pro ... l-repeater

Otherwise, it's necessary to adapt your VBScript to Javascript.
Check the following links, you can get an idea of how to read an XML.
viewtopic.php?t=1997
viewtopic.php?f=12&t=1201&p=4080&hilit=Xslt+split#p4080
viewtopic.php?f=12&t=1276&p=4354#p4352
viewtopic.php?t=1661
viewtopic.php?f=13&t=4071
joaodaffonsojr
Member
Posts: 23
Joined: Wed Sep 08, 2021 4:36 pm

Re: VBscript variable to income job

Post by joaodaffonsojr »

Hi !

I found a solution instead converting to javascript.

1st I created a variable in the script to get [Job.NameProper]
1.png
1.png (33.18 KiB) Viewed 5198 times
2nd I found the Auto_managed folder path for input and output files.

3rd then it was just to put everything in their respective places, and Voilà !

It´s working !

Thanks guys !
Post Reply