Package creation from Workflow | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by CedricRey

Hello,

Here is an example of JS code that generate a package as XML File :

var packageName = "myPackage"; //export delivery with internalName 'DM123456' var schema = "nms:delivery"; var conditionExpression = "@internalName = 'DM123456'"; specFileDef = { specFile : { definition : { schema : schema, where : { condition : [{ "expr" : conditionExpression }] } } } }; var specFile = NLWS.xtkSpecFile.create( specFileDef ); //Package generation var package = specFile.GenerateDoc(); //Save content in a file var packageBuffer = new MemoryBuffer(); packageBuffer.fromString ( package.toXMLString() ); //File name with date included : packageBuffer.save( packageName + "_" + formatDate( new Date(), "%4y%2M%2D") + ".xml" );

The package will be the same as if you export with the console.

 

Cedric

2 replies

Jonathon_wodnicki
Community Advisor
Community Advisor
May 4, 2021

Hi,

 

Use a js activity with the code from that doc page.

Here's a simplified example from a library I wrote once that managed packaging and vcs:

var selectionExport = xtk.specFile.exportSelection(schema, <where> <condition expr={condition}/> </where>); var f = new File(filepath); f.open('w'); f.writeln('<package buildNumber="' + buildNumber + '" buildVersion="' + buildVersion + '">'); f.writeln(selectionExport.entities.toXMLString()); f.writeln('</package>'); f.close();

The exportSelection() endpoint is in xtk:package.js btw if you want to see how it works.

 

Thanks,

-Jon

adithyacs86
Level 5
May 4, 2021
Hi , Thanks for the inputs on this, Sure will try to work on this code and look more in the package.js. Much helpful thank you !!!
CedricRey
CedricReyAccepted solution
Level 5
May 4, 2021

Hello,

Here is an example of JS code that generate a package as XML File :

var packageName = "myPackage"; //export delivery with internalName 'DM123456' var schema = "nms:delivery"; var conditionExpression = "@internalName = 'DM123456'"; specFileDef = { specFile : { definition : { schema : schema, where : { condition : [{ "expr" : conditionExpression }] } } } }; var specFile = NLWS.xtkSpecFile.create( specFileDef ); //Package generation var package = specFile.GenerateDoc(); //Save content in a file var packageBuffer = new MemoryBuffer(); packageBuffer.fromString ( package.toXMLString() ); //File name with date included : packageBuffer.save( packageName + "_" + formatDate( new Date(), "%4y%2M%2D") + ".xml" );

The package will be the same as if you export with the console.

 

Cedric

adithyacs86
Level 5
May 4, 2021
Hi Rey, Thank you for this example and will check by implementing this. Regards, Adithya