Injecting files using a Script_SOLVED

Post Reply
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Injecting files using a Script_SOLVED

Post by victor Lukenga »

Hello,

Im trying to inject files via my metadatas I have some issues

when I use the built-in inject tool I can import only the first file (I don't know if my XML is well writed ) when I choose the "files" node switch don't seem to read through the entire node

Code: Select all

	
	Xml:	
		<files>
			<file>
				<path>C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxx/ORDxxxx/docs/xxxxx1.pdf</path>
				<path>C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxx/ORDxxxx/docs/xxxxx2.pdf</path>
			</file>
		</files>
That's why I turned myself to scripting:

Code: Select all


function jobArrived( s : Switch, job : Job )
{
	
var dataset = job.getDataset('Xml');
//var path = dataset.evalToString('/order/files');
var dummyPath =( 'C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxxx/ORxxxxxxx/docs/xxxxx1.pdf'); // for testing


job.sendToSingle(dummyPath);

}

The issues are :

the injected file is cleared from his original location(we have to keep the customers files )
the original name and extention are replaced or disapear
Only one file is imported


I can figure this out hope you will help me :)

Best regards :geek:
Last edited by victor Lukenga on Thu Mar 24, 2016 9:50 am, edited 2 times in total.
sander
Advanced member
Posts: 228
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: /!\ Injecting files using a Scripting

Post by sander »

You can't loop through nodes in Switch. Do you generate the XML by yourself?

Than the easiest approach is to create one XML for each file, which you can easily use with inject job.

Code: Select all

      <files>
         <file>
            <path>C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxx/ORDxxxx/docs/xxxxx1.pdf</path>
         </file>
      </files>
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.

Chat: open-automation @ gitter
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

Hi , thank you to take time to answer I really appreciate it

these Xmls are generated by a home made app

one xml per file is a bit complicated, cause all files contained in the "docs" folder are part of one order : we may have e.g 2 files for one business card
(fileRecto.pdf fileVerso.pdf)
the best way for me will be to loop through "files" node. I've tried and spend few hours to find a solution : answer is close to me but where :)
sander
Advanced member
Posts: 228
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: /!\ Injecting files using a Scripting

Post by sander »

I used to do it this way, without scripting: http://forum.enfocus.com/viewtopic.php?f=12&t=1201

Since Switch 13 I upgraded to the Saxon configurator: http://forum.enfocus.com/viewtopic.php?f=12&t=1237

So it's already done without scripting. Keep it simple ;)
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.

Chat: open-automation @ gitter
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

Yes this is my keyword too "keep it simple"

Ive just tried to run the saxon configurator but it return this

Code: Select all

Flow validation error: The application is not available on Switch Server
?

I also donwload the version you provided on you post

I guess that saxon is open source ?
sander
Advanced member
Posts: 228
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: /!\ Injecting files using a Scripting

Post by sander »

Running on Windows too?

Did you restart Switch / search for applications?

And yes, it's open source.
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.

Chat: open-automation @ gitter
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

Yes I'm on windows

I unistall /reinstall it : Strange I keep have the same error :/
sander
Advanced member
Posts: 228
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: /!\ Injecting files using a Scripting

Post by sander »

My Switch server is running on Windows Server 2012 R2 with only .NET Framework 4.5 installed, no 3.5 or earlier versions.

4.5 is not installed by default, do you have it?
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.

Chat: open-automation @ gitter
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

[quote="sander"]My Switch server is running on Windows Server 2012 R2 with only .NET Framework 4.5 installed, no 3.5 or earlier versions.

Edit : I rebooted my machine : the configurator is now working
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

I wondered if evalToNodes can be suitable for my needs ?

Code: Select all



function jobArrived( s : Switch, job : Job )
{

var dataset = job.getDataset('Xml');
	
var xml = new Document(dataset);

var node = xml.evalToNodes('/order/files/file');


if(dataset != null){
	
	
	for (var i=0; i < node.length; i++) {

		var myNode = node.getItem(i);
    	var files = myNode.evalToString(".");
		
		job.log(2, "files are "+theNode.evalToString("."));

		job.sendToSingle();}


}else{}


}
sander
Advanced member
Posts: 228
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: /!\ Injecting files using a Scripting

Post by sander »

Yes this can be done, however I personally haven't done this yet. On the list to figure out later, little busy :)

But I'm sure some other more experienced scripting forum members can help you out.

Curious, did you get it to work with the Saxon transform?
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.

Chat: open-automation @ gitter
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

thank you for your answer :)

I tried to play with Saxon but honestly I don't have experience in XSLT so I didn't understand how to setup Saxon.
sander
Advanced member
Posts: 228
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: /!\ Injecting files using a Scripting

Post by sander »

Based on your given XML example I would do this ;)

Configure Saxon like this;
Image

With this as content of your victor.xsl:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
    <xsl:template match="/">
        <xsl:for-each select="files/file/path">
        	<xsl:variable name="InputFile" select="base-uri()"/>
			<xsl:variable name="OutputFile" select="tokenize($InputFile,'/')[last()]"/>
        	<xsl:variable name="OutputNoExt" select="substring-before($OutputFile,'.')"/>
	    	<xsl:result-document href="{$OutputNoExt}_{format-number(position(),'000')}.xml" method="xml">
			<xsl:copy-of select="current()"/>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
Your input XML...

Code: Select all

<files>
	<file>
	<path>C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxx/ORDxxxx/docs/xxxxx1.pdf</path>
	<path>C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxx/ORDxxxx/docs/xxxxx2.pdf</path>
	</file>
</files>
... will result in this two output XML's:

jobname_001.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<path>C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxx/ORDxxxx/docs/xxxxx1.pdf</path>
jobname_002.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<path>C:/Users/flprint-switch/Desktop/checker/ORDxxxxxxx/ORDxxxx/docs/xxxxx2.pdf</path>
Does that help?
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.

Chat: open-automation @ gitter
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

that's great

Ill give a try this week end I will also give you a feedback

Once Again Thank you for your help !
victor Lukenga
Member
Posts: 21
Joined: Thu Feb 18, 2016 1:35 pm

Re: /!\ Injecting files using a Scripting

Post by victor Lukenga »

Hi Sander,

Thanks a lot for your help! it works like a charm it was exaclty what I needed!! wonderful forum !! ;) :mrgreen: :mrgreen: :mrgreen: .


thank you again !
Post Reply