Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Working on a folder level Js and getting this error NotAllowedError:

Community Beginner ,
Feb 22, 2023 Feb 22, 2023

Working on my first folder level javascricpt at the moment and running into an issue with NotAllowedError: Security settings prevent access to this property or method. Any tips on escalating do i need to run in the apps folder rather than user? 

// Define the file path and name of the .csv file
var filePath = "/G/acro/sheet.csv";

// Define the delimiter used in the .csv file
var delimiter = ",";

// Open the .csv file
var file = app.openDoc(filePath);

// Get the contents of the .csv file
var contents = file.extractText();

// Split the contents into an array of rows
var rows = contents.split('\n');

// Loop through each row and create a corresponding text field
for (var i = 0; i < rows.length; i++) {
  // Split the row into an array of values
  var values = rows[i].split(delimiter);
  
  // Create a new text field with a unique name
  var fieldName = "text" + i;
  this.addField(fieldName, "text", i, [50, 700, 200, 730]);
  
  // Set the value of the text field to the corresponding value from the .csv file
  this.getField(fieldName).value = values[0];
}

Thank you very much for taking the time to look at this!

TOPICS
How to , JavaScript
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2023 Feb 22, 2023

The openDoc method can only be used on PDF files, and there's no "extractText" method in Acrobat.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2023 Feb 22, 2023

If you want to read the contents of a text file use util.readFileIntoStream().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 23, 2023 Feb 23, 2023

Ive switched it to readFileIntoStream but I am now recieving this error

(NotAllowedError: Security settings prevent access to this property or method.
Util.readFileIntoStream:8:Folder-Level) 

I am currently running the script in the user folder do i need to switch to the app folder thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2023 Feb 23, 2023
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2023 Feb 23, 2023
LATEST

I suggest you run it from the Console first (which is in a privileged context) to see that it works.

Then deal with the trust issues.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines