Jobsort based on XML metadata
Posted: Sat Feb 01, 2014 2:23 pm
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;
}
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;
}