Skip to main content
ukender
Level 3
Jan 4, 2022 10:27 AM UTC
Solved

Nee help to read multiple files from nlserver module

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.
Krishnanunni
KrishnanunniAccepted solution
Level 4
Jan 6, 2022 4:42 AM UTC

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;
   }   
}

13 replies

Jyoti_Yadav
Level 8
Jan 4, 2022 10:59 AM UTC

Hi @ukender 

 

Try with below script:

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

 

Thanks,

Jyoti

 

Translate
ukender
ukenderAuthor
Level 3
Jan 4, 2022 11:35 AM UTC

Hi Jyoti

 

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

 

Thank you!

Translate
Jyoti_Yadav
Level 8
Jan 4, 2022 12:35 PM UTC

Hi @ukender ,

 

You can use the command: ls -la to list all the files.

Once you have the name and number of files, run the loop to pick each file name and then execute your command.

 

What is your purpose to run this command? May be you can use some alternative suggestion as well.

 

Thanks,

Jyoti

Translate
adithyacs86
Level 5
Jan 4, 2022 1:39 PM UTC

Hi Ukender, 

 

Did you try the File transfer activity.  

 

 

Thanks,
Adithya

 

Translate
ukender
ukenderAuthor
Level 3
Jan 4, 2022 2:48 PM UTC

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!

Translate
adithyacs86
Level 5
Jan 4, 2022 2:55 PM UTC

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

Translate
Krishnanunni
KrishnanunniAccepted solution
Level 4
Jan 6, 2022 4:42 AM UTC

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;
   }   
}
Translate
ukender
ukenderAuthor
Level 3
Jan 6, 2022 5:45 AM UTC

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!

Translate
Krishnanunni
Level 4
Jan 6, 2022 7:56 AM UTC

@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.

Translate
Sukrity_Wadhwa
Level 4
Jan 13, 2022 10:42 AM UTC

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!

Translate
Sukrity Wadhwa