Compose XML for HTTP POST using file in hot folder
-
- Member
- Posts: 25
- Joined: Mon Mar 09, 2020 10:22 pm
Compose XML for HTTP POST using file in hot folder
I have a task I'm not sure how to tackle so I am seeking advice on how to approach the following:
1. I need to be able to pick up a file from a hot folder and from the file name extract a portion of the name from the file path
2. The Naming convention is 000000-00_000_0-C-Y.pdf. I only need the first section before the "_" which is a job name which is all numeric
3. I need to extract the last digit from the six digits in the Job name that come before the "-" in order to select a server name for the HTTP POST URL
4. I need to compose the XML for the POST body and put it in the parameters
5. Send the POST and if the response is not 200 OK send a failure email.
I'm looking for advice on flow structure and how to utilize regular expressions to extract the file components. I'm very weak with javascript, but have experience with VB.net. I would prefer to utilize Switch Apps rather than scripting, but that may not be possible. Please Advise.
1. I need to be able to pick up a file from a hot folder and from the file name extract a portion of the name from the file path
2. The Naming convention is 000000-00_000_0-C-Y.pdf. I only need the first section before the "_" which is a job name which is all numeric
3. I need to extract the last digit from the six digits in the Job name that come before the "-" in order to select a server name for the HTTP POST URL
4. I need to compose the XML for the POST body and put it in the parameters
5. Send the POST and if the response is not 200 OK send a failure email.
I'm looking for advice on flow structure and how to utilize regular expressions to extract the file components. I'm very weak with javascript, but have experience with VB.net. I would prefer to utilize Switch Apps rather than scripting, but that may not be possible. Please Advise.
-
- Member
- Posts: 94
- Joined: Fri Jul 08, 2011 10:31 am
- Location: The Netherlands
Re: Compose XML for HTTP POST using file in hot folder
Hi teetomterrific,
I think this should work. (Not tested)
1) Very easy with Switch
2) Use this variable [Job.NameProper:Before="_"] and store it in private data
3) Use this variable [Job.NameProper:Search="\d{1}(?=-)"] and store it in private data
4) Compose the XML with the app "Create text file" or "Create file from template". They are in the app-store.
5) Do the post with Data = script.expression
I think this should work. (Not tested)
1) Very easy with Switch
2) Use this variable [Job.NameProper:Before="_"] and store it in private data
3) Use this variable [Job.NameProper:Search="\d{1}(?=-)"] and store it in private data
4) Compose the XML with the app "Create text file" or "Create file from template". They are in the app-store.
5) Do the post with Data = script.expression
Code: Select all
jobBody = File.read(job.getPath(),"UTF-8");
jobBody;
Re: Compose XML for HTTP POST using file in hot folder
One improvement to Robert's answer to number 5: you can avoid the use of a script expression by using v20 of HTTP request and choosing "POST a body - Input job".
-
- Member
- Posts: 25
- Joined: Mon Mar 09, 2020 10:22 pm
Re: Compose XML for HTTP POST using file in hot folder
I ended up doing everything in a script which works great except I need for Switch to not add the prefix to the file name. When I set the Input folder to "leave originals in place" the path served up by Switch preserves the prefix and the prefix remains the same in the path Switch provides to the script, but the name is unchanged in the input folder so processing of the file from the post I send fails because the path is incorrect for the real filename path which was unchanged as requested. Is this a bug? Is there anyway to make Switch provide the correct path without the the unique job prefix and not have to do string manipulation?
Re: Compose XML for HTTP POST using file in hot folder
Switch always add a unique prefix to a job. If you need the name without the prefix there is job.getName(true/false) where the boolean value is if you want the job name with or without the extension.
-
- Member
- Posts: 25
- Joined: Mon Mar 09, 2020 10:22 pm
Re: Compose XML for HTTP POST using file in hot folder
@ffeddyp you misunderstand my need. I need the input file that has the prefix added to NOT have the prefix added so that the filename is not modified. The filename begins with our internal job name and that must remain at the beginning of the name and the remainder of the name cannot be modified because it is a specific pattern that our automation needs to interpret correctly. I have tried changing the setting that says not to modify it, but that changes the path to be an internal path and not the file's real hot folder path so the path in the HTTP POST I send is wrong and the destination app cannot find the file. I have no problem getting the true filename using the command job.getNamePropper and getting the path with job.getPath. It is the modification to the true filename I need to not be modified and the path reported correctly when that option is selected OR some method that will remove the prefix before the script is run. This is some maddening BS that there is no obvious workaround like sting the unique ID in Private Data instead of physically renaming a file.
Re: Compose XML for HTTP POST using file in hot folder
Can't you send the file to a folder on disc at the end of a connection, then the prefix is gone. Then you will have the correct path.
-
- Member
- Posts: 25
- Joined: Mon Mar 09, 2020 10:22 pm
Re: Compose XML for HTTP POST using file in hot folder
The file comes in to a hot folder on a NAS, The script is the next action. The file never leaves the hot folder. It will be picked up by the POST destination server. It will never get to another folder. The script has to read where the file is and that must be on a network path, not an internal Switch folder. Moving to a different folder changes the path that the POST has already provided to the destination so that server will fail to pickup the file since it has moved.
Re: Compose XML for HTTP POST using file in hot folder
But you can send a copy of the file to one folder at the end of the connection and another copy to do the rest the flow.
-
- Member
- Posts: 25
- Joined: Mon Mar 09, 2020 10:22 pm
Re: Compose XML for HTTP POST using file in hot folder
I fail to understand how that would work. Switch physically modifies the filename on the storage device adding the unique prefix. That alters the file path. How would making copies of the file change that when switch serves up that modified path when the script calls job.getPath(). This flow has just one action attached to the input hot folder which is the script. Adding copies means I have to mange/delete copies, which is stupid. I just need to disable the prefix and have Switch serve up the correct path and not some internal path location that happens when I disable the prefix and doesn't really exist. The Flow never does anything but run the script and the prefix is completely unnecessary as well as never used. I do not need to add unnecessary steps to a badly designed unique ID process that when disabled should actually be disabled instead of changing the path behavior to a bogus path when the file is still sitting in the freaking hot folder with the correct name.
Re: Compose XML for HTTP POST using file in hot folder
The copy is sent to a folder that ends there on the disc. No connections out of the folder. Then Switch think it is done with that job and leave it with its original filename, no prefix.
Now you can use it with your script. The resto of the flow continue with its tasks.
Now you can use it with your script. The resto of the flow continue with its tasks.
-
- Member
- Posts: 25
- Joined: Mon Mar 09, 2020 10:22 pm
Re: Compose XML for HTTP POST using file in hot folder
This makes no sense to me. I would have to see an example that makes the ID go away because everything I try the path still has the stupid unique ID as part of the file name.jan_suhr wrote: ↑Tue May 07, 2024 8:05 am The copy is sent to a folder that ends there on the disc. No connections out of the folder. Then Switch think it is done with that job and leave it with its original filename, no prefix.
Now you can use it with your script. The resto of the flow continue with its tasks.
- magnussandstrom
- Advanced member
- Posts: 380
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Compose XML for HTTP POST using file in hot folder
On the output folder there is a property called 'Strip unique name' set that to 'Yes'.
- magnussandstrom
- Advanced member
- Posts: 380
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Compose XML for HTTP POST using file in hot folder
Why bother with a script when there is an out of the box solution?
-
- Member
- Posts: 25
- Joined: Mon Mar 09, 2020 10:22 pm
Re: Compose XML for HTTP POST using file in hot folder
The script does more than send the Post. It also determines which Server out of 5 the POST needs to be sent to and formats the server URL by using Regular Expressions to pull the last digit of the Job name to a select case for the server. It's not the actual POST I have issues with. It is not being able to disable the silly unique ID.magnussandstrom wrote: ↑Tue May 07, 2024 2:53 pm Why bother with a script when there is an out of the box solution?
I have tried your suggestion to connect the input folder to an output folder and set the 'Strip unique name' to yes. However as soon as I connect that output folder to the script all the folder properties change and the Strip unique name' is no longer available as a property of the folder and it keeps the prefix. That inconsistency is maddening.