sort files out from the value in linked XML file

Post Reply
Jarmer
Newbie
Posts: 12
Joined: Mon Feb 23, 2015 3:47 pm

sort files out from the value in linked XML file

Post by Jarmer »

Hi

How can i sort files that have a value that is higer/less or equal to the value in the linked XML file.

For example:

XML have value 100 and need to go to folder A that is for files that is less that the value 500.
XML have value 1000 and need to go to folder B that is for files that is higer than the value 500
XML have value 500 and need to go to folder C that is for files that is equal with the value 500.

Thanks

Reé
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: sort files out from the value in linked XML file

Post by gabrielp »

You can read the XML information as a variable. Once it's a variable, you can sort the job via connector include/exclude criteria.

- Put your XML file in a folder.
- Route the jobs from that folder through an XML Pickup.
---- Set the "Dataset name" to "My XML Dataset"
- Route the jobs from the XML Pickup into another folder
- Route the jobs from the outbound folder into two more folders
- Change these connector colors to blue, to signify they are not including "all jobs"
- Edit the first connector, changing "Include these jobs" to "define condition with variables"
- On the left side of the condition, hit the [...]
---- If you are sorting based on a number
-------- Choose Switch > Calculation > Expression > [ > ] > Define single line text with variables
-------- Choose Metadata > Text > Path > [ > ] > Build location path > click on "My XML Dataset" > click on the value > OK > Insert variable > OK
---- If you are sorting based on a text value
-------- Choose Metadata > Text > Path > [ > ] > Build location path > click on "My XML Dataset" > click on the value > OK > Insert variable > OK
- On the right side condition, select the condition that jobs will route this way if evaluates to true. For example, if your number is a Switch calculation that returns 400, and you say greater than 500 as your right side condition, this job will not route this way.
- For the other connector, set all other jobs to be included

Now your flow should be routing based on the XML value. You can tweak those conditions to make them more complex.

Image

But a good next step is to stop right here and write that XML value to a private data value. Selecting that dataset value via build location path is a pain in the ass, and if you XML schema ever changes, you're gonna have to fix it in a lot of places in your flow. Instead, if you use a script like switch-private-data-write to write the value to a private data key, you can reference that key within the flow. Now, you can just update it in one place and have the benefit of simply referencing the private data key, which is quicker and easier to read. If you're interested in learning more about this, I recommend you check out this page: https://github.com/open-automation/swit ... -practices
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: sort files out from the value in linked XML file

Post by freddyp »

One remark for improvement. gabrielp wrote
---- If you are sorting based on a number
-------- Choose Switch > Calculation > Expression > [ > ] > Define single line text with variables
-------- Choose Metadata > Text > Path > [ > ] > Build location path > click on "My XML Dataset" > click on the value > OK > Insert variable > OK
You can shorten this a bit by accessing the metadata directly with the correct type:
---- If you are sorting based on a number
-------- Choose Metadata >Integer/Rational > Path > [ > ] > Build location path > click on "My XML Dataset" > click on the value > OK > Insert variable > OK
Jarmer
Newbie
Posts: 12
Joined: Mon Feb 23, 2015 3:47 pm

Re: sort files out from the value in linked XML file

Post by Jarmer »

Hi, thanks for your help....most helpfull....
Post Reply