Nee help to read multiple files from nlserver module | Community
Skip to main content
ukender
Level 3
January 4, 2022
Solved

Nee help to read multiple files from nlserver module

  • January 4, 2022
  • 4 replies
  • 3368 views

Hi All

 

Can anyone please help me to understand, how to read multiple files from the SFTP location. the below command picks one file per run.

 

package -instance: [instance_name] -export:sftp/adobe/export/test.xml -spec:cus:PKGXXX -verbose

 

Note: The above script is used in nlserver module.

Thank you!

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 Krishnanunni

Hi @ukender ,

If the purpose is to export packages, then I think you may be able to use the JS code. I had defined my packages in package definition. So the following code would export packages in package definition one by one. We can filter out any packages based on the namespace or package name.

var query = xtk.queryDef.create(

<queryDef schema="xtk:specFile" operation="select">
  <select>
  <node expr="@name"/>
  <node expr="@namespace"/>
  <node expr="data"/>
  </select>
</queryDef>
);

var res = query.ExecuteQuery();
var exported = 0;
for (var i = 0;i<Object.keys(res).length; i++){
  logInfo("Exporting Package " + res[i].@name + " to xml");
  if(res[i].@namespace == "cus") {
    try{
      var specFile = xtk.specFile.create(res[i]);
      var package = specFile.GenerateDoc();
      var fileName = "<SFTP path>/PKG_" + res[i].@name.toLowerCase() + ".xml";
      saveXmlFile(package, fileName);
      exported++;
     }catch(err){
           logWarning("Package " + res[i].@name + "has not been exported due to an error.");
     }
   } else {
      continue;
   }   
}

4 replies

Jyoti_Yadav
Level 8
January 4, 2022

Hi @ukender 

 

Try with below script:

package -instance: [instance_name] -export:sftp/adobe/export/*.xml -spec:cus:PKGXXX -verbose

 

Thanks,

Jyoti

 

ukender
ukenderAuthor
Level 3
January 4, 2022

Hi Jyoti

 

Thanks for the response, I have tried that option but it is expecting the proper file name in nlmodule.

 

Thank you!

Jyoti_Yadav
Level 8
January 5, 2022

Hi Jyoti

Trying to import / export the package files thru workflow using nlserver module. It is perfectly working if we define a single file for import from sftp location but finding difficulties to fetch multiple files, tried the below options but no success.

Able to write the file names using JS activity after the file collector but unsure how to feed multiple files to nlserver module.

 

package -instance: [instance_name] -import:sftp/adobe/export/*.xml -verbose
package -instance: [instance_name] -import:sftp/adobe/export/*.* -verbose

Thank you!


Hi @ukender ,

 

Even if you are able to read all the files at once, you will be able to process one file at a time. So instead of using nlserver module, you can use:

1) File Collector activity which will pick the file. Once file is picked move them to different location. Also, check "Stop as soon as file is processed". This will make sure to stop once all the files are read and imported.

2) Test activity to check if there's any file present to import.

3) Data Loading activity which will read the files coming from File Collector.

4) Load data of the file.

5) Loop back the workflow to File Collector.

 

Thanks,

Jyoti

adithyacs86
Level 5
January 4, 2022

Hi Ukender, 

 

Did you try the File transfer activity.  

 

 

Thanks,
Adithya

 

ukender
ukenderAuthor
Level 3
January 4, 2022

Hi Adithya,

Thanks for the response, would like to understand how to count the number of files available in the directory and feed the xml name dynamically in nlserver module.

Thank you!

adithyacs86
Level 5
January 4, 2022

Hi Ukender, 

 

Not sure if you have to really use the nlserver module for SFTP things. 

 

Can you check if you can use something like below in JS 

logInfo(execCommand("ls -ls /usr/local/neolane.../<your directory to search for the files>"))

 

Thanks,
Adithya

Krishnanunni
KrishnanunniAccepted solution
Level 4
January 6, 2022

Hi @ukender ,

If the purpose is to export packages, then I think you may be able to use the JS code. I had defined my packages in package definition. So the following code would export packages in package definition one by one. We can filter out any packages based on the namespace or package name.

var query = xtk.queryDef.create(

<queryDef schema="xtk:specFile" operation="select">
  <select>
  <node expr="@name"/>
  <node expr="@namespace"/>
  <node expr="data"/>
  </select>
</queryDef>
);

var res = query.ExecuteQuery();
var exported = 0;
for (var i = 0;i<Object.keys(res).length; i++){
  logInfo("Exporting Package " + res[i].@name + " to xml");
  if(res[i].@namespace == "cus") {
    try{
      var specFile = xtk.specFile.create(res[i]);
      var package = specFile.GenerateDoc();
      var fileName = "<SFTP path>/PKG_" + res[i].@name.toLowerCase() + ".xml";
      saveXmlFile(package, fileName);
      exported++;
     }catch(err){
           logWarning("Package " + res[i].@name + "has not been exported due to an error.");
     }
   } else {
      continue;
   }   
}
ukender
ukenderAuthor
Level 3
January 6, 2022

Thank you for your inputs @krishnanunni. I will try that option, Is it possible to import the exported xml package from an SFTP location?
If you have an idea pls share it, would be really helpful.

Thank you!

Krishnanunni
Level 4
January 6, 2022

@ukender ,

I haven't used it but the xtk.builder InstallPackage function might be useful for this. Please see the below function:
https://experienceleague.adobe.com/developer/campaign-api/api/sm-builder-InstallPackage.html.

You may try reading the xml file and passing the content to the installpackage function.

Sukrity_Wadhwa
Community Manager
Community Manager
January 13, 2022

Hi @ukender,

Were you able to resolve this query with any of the given solutions or do you still need more help here? Do let us know.
Thanks!

Sukrity Wadhwa