Hi, i tried to modify a example script for my flow, but something is wrong in the code.
The error-message is : Error in line 23 of script : Error. Use of undefined variable 'theXML'
It was a flow for xmp and i changed only xmp to xml. Has anyone an idea what i have to change to get this working?
// 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 : Switch, job : Job )
{
// Get the xml dataset associated with this job
var theXml = job.getDataset("XML");
// Only search for a valid outgoing connection if we have XML information in the job in the first place
var theResultConnection = null;
if (theXML != null) {
// Get the value of the XML property we're looking for
var theSortKey = s.getPropertyValue('argSortExpression');
var theSortValue = theXML.getString( theSortKey , null );
if (theSortValue != null) {
s.log( 1, theSortKey + " = " + theSortValue );
theResultConnection = getConnectionByName( s, theSortValue );
} else {
s.log( 1, "XML information for " + theSortKey + " was not found for this job" );
}
} else {
s.log( 1, "No XML information found associated with this job" );
}
// If we found a connection, move the job there. If not move it to the data error connections
if (theResultConnection != null) {
job.sendTo( theResultConnection, job.getPath() );
s.log( 1, "Connection with correct name found; moved job" );
} else {
job.sendToData( 3, job.getPath() );
s.log( 1, "No valid connection found, moved job to error output" );
}
}
// ==================================================================================================
// This function gets the full list of outgoing connections for the given script element and searches through this list for a connection with a given name.
// If such a connection is found it is returned, if nothing is found this function returns null.
// ==================================================================================================
function getConnectionByName( s: Switch, connectionName: String ): Connection
{
var theConnections = s.getOutConnections();
for (var i = 0; i < theConnections.getCount(); i++) {
// Get this connection
var theConnection = theConnections.at(i);
if (theConnection.getName() == connectionName) {
return theConnection;
}
}
return null;
}
Jobsort based on XML metadata
Jobsort based on XML metadata
Javascript variables are case-sensitive:
var theXml = ...
if (theXML ...
That is indeed not going to work.
Freddy
var theXml = ...
if (theXML ...
That is indeed not going to work.
Freddy
Jobsort based on XML metadata
Hi, i changed it, sadly i have a new error.
Error in line 14 of script : TypeError. 'getString' undefined or not a function.
For me is looks good, but somewhere must be a little bug.
Here is my flow: https://www.dropbox.com/s/497taif1k8ih9 ... enshot.jpg
// 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 : Switch, job : Job )
{
// Get the xml dataset associated with this job
var theXml = job.getDataset("Xml");
// Only search for a valid outgoing connection if we have XML information in the job in the first place
var theResultConnection = null;
if (theXml != null) {
// Get the value of the XML property we're looking for
var theSortKey = s.getPropertyValue('argSortExpression');
var theSortValue = theXml.getString( theSortKey , null );
if (theSortValue != null) {
s.log( 1, theSortKey + " = " + theSortValue );
theResultConnection = getConnectionByName( s, theSortValue );
} else {
s.log( 1, "XML information for " + theSortKey + " was not found for this job" );
}
} else {
s.log( 1, "No XML information found associated with this job" );
}
// If we found a connection, move the job there. If not move it to the data error connections
if (theResultConnection != null) {
job.sendTo( theResultConnection, job.getPath() );
s.log( 1, "Connection with correct name found; moved job" );
} else {
job.sendToData( 3, job.getPath() );
s.log( 1, "No valid connection found, moved job to error output" );
}
}
// ==================================================================================================
// This function gets the full list of outgoing connections for the given script element and searches through this list for a connection with a given name.
// If such a connection is found it is returned, if nothing is found this function returns null.
// ==================================================================================================
function getConnectionByName( s: Switch, connectionName: String ): Connection
{
var theConnections = s.getOutConnections();
for (var i = 0; i < theConnections.getCount(); i++) {
// Get this connection
var theConnection = theConnections.at(i);
if (theConnection.getName() == connectionName) {
return theConnection;
}
}
return null;
}
And her is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<import version="1.0">
<pos>
<artikel>
<options>
<auflage>50 Stck</auflage>
<papier>300_Bilderdruck_matt</papier>
</options>
</artikel>
</pos>
</import>
Error in line 14 of script : TypeError. 'getString' undefined or not a function.
For me is looks good, but somewhere must be a little bug.
Here is my flow: https://www.dropbox.com/s/497taif1k8ih9 ... enshot.jpg
// 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 : Switch, job : Job )
{
// Get the xml dataset associated with this job
var theXml = job.getDataset("Xml");
// Only search for a valid outgoing connection if we have XML information in the job in the first place
var theResultConnection = null;
if (theXml != null) {
// Get the value of the XML property we're looking for
var theSortKey = s.getPropertyValue('argSortExpression');
var theSortValue = theXml.getString( theSortKey , null );
if (theSortValue != null) {
s.log( 1, theSortKey + " = " + theSortValue );
theResultConnection = getConnectionByName( s, theSortValue );
} else {
s.log( 1, "XML information for " + theSortKey + " was not found for this job" );
}
} else {
s.log( 1, "No XML information found associated with this job" );
}
// If we found a connection, move the job there. If not move it to the data error connections
if (theResultConnection != null) {
job.sendTo( theResultConnection, job.getPath() );
s.log( 1, "Connection with correct name found; moved job" );
} else {
job.sendToData( 3, job.getPath() );
s.log( 1, "No valid connection found, moved job to error output" );
}
}
// ==================================================================================================
// This function gets the full list of outgoing connections for the given script element and searches through this list for a connection with a given name.
// If such a connection is found it is returned, if nothing is found this function returns null.
// ==================================================================================================
function getConnectionByName( s: Switch, connectionName: String ): Connection
{
var theConnections = s.getOutConnections();
for (var i = 0; i < theConnections.getCount(); i++) {
// Get this connection
var theConnection = theConnections.at(i);
if (theConnection.getName() == connectionName) {
return theConnection;
}
}
return null;
}
And her is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<import version="1.0">
<pos>
<artikel>
<options>
<auflage>50 Stck</auflage>
<papier>300_Bilderdruck_matt</papier>
</options>
</artikel>
</pos>
</import>
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Jobsort based on XML metadata
When you created the script did you add a property named 'argSortExpression'?
Also, I made 2 changes to your script
function jobArrived( s : Switch, job : Job )
{
// Get the xml dataset associated with this job
var theXml = job.getDataset("Xml");
// Only search for a valid outgoing connection if we have XML information in the job in the first place
var theResultConnection = null;
if (theXml.hasValidData( )) {
// Get the value of the XML property we're looking for
var theSortKey = s.getPropertyValue('argSortExpression');
var theSortValue = theXml.evalToString( theSortKey , null );
if (theSortValue != null) {
s.log( 1, theSortKey + " = " + theSortValue );
theResultConnection = getConnectionByName( s, theSortValue );
} else {
s.log( 1, "XML information for " + theSortKey + " was not found for this job" );
}
} else {
s.log( 1, "No XML information found associated with this job" );
}
// If we found a connection, move the job there. If not move it to the data error connections
if (theResultConnection != null) {
job.sendTo( theResultConnection, job.getPath() );
s.log( 1, "Connection with correct name found; moved job" );
} else {
job.sendToData( 3, job.getPath() );
s.log( 1, "No valid connection found, moved job to error output" );
}
}
Also, I made 2 changes to your script
function jobArrived( s : Switch, job : Job )
{
// Get the xml dataset associated with this job
var theXml = job.getDataset("Xml");
// Only search for a valid outgoing connection if we have XML information in the job in the first place
var theResultConnection = null;
if (theXml.hasValidData( )) {
// Get the value of the XML property we're looking for
var theSortKey = s.getPropertyValue('argSortExpression');
var theSortValue = theXml.evalToString( theSortKey , null );
if (theSortValue != null) {
s.log( 1, theSortKey + " = " + theSortValue );
theResultConnection = getConnectionByName( s, theSortValue );
} else {
s.log( 1, "XML information for " + theSortKey + " was not found for this job" );
}
} else {
s.log( 1, "No XML information found associated with this job" );
}
// If we found a connection, move the job there. If not move it to the data error connections
if (theResultConnection != null) {
job.sendTo( theResultConnection, job.getPath() );
s.log( 1, "Connection with correct name found; moved job" );
} else {
job.sendToData( 3, job.getPath() );
s.log( 1, "No valid connection found, moved job to error output" );
}
}
Jobsort based on XML metadata
I see no reason to use a script for what you are doing. On each of the connections you can easily put a condition with variable, where on the left-hand side you have:
[Metadata.Text:Path="/import/pos/artikel/options/papier",Dataset="Xml",Model=XML]
As an operator you have "Starts with".
And on the right-hand side you have "300_" (or another combination of operator and string that is more suited).
Freddy
[Metadata.Text:Path="/import/pos/artikel/options/papier",Dataset="Xml",Model=XML]
As an operator you have "Starts with".
And on the right-hand side you have "300_" (or another combination of operator and string that is more suited).
Freddy
Jobsort based on XML metadata
Thank you both for your help, i will consider your tips. Thanks a lot.