Skip to main content
New Participant
February 5, 2025
Answered

app.alert undefined when using "Run a Javascript"

  • February 5, 2025
  • 1 reply
  • 3316 views

Hello,

 

I am attempting to get app.alert to display a message onscreen via the "Run a Javascript" menu option. Currently the contents do not matter, so I have been using the sample code provided in https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#alert

My code is as follows:

 

app.alert({
cMsg: "Error! Try again!",
cTitle: "Acme Testing Service"
});

 

When this code is run with the right click menu > "Run a Javascript", it returns:

Line: 1: Code: 2(0x2): app is undefined
Line: 1: Code: 21(0x15): undefined is not an object

 

When run through the console, the code functions as expected.

When saved to C:\Program Files\Adobe\Acrobat DC\Acrobat\Javascripts the code runs on first start up of Adobe Acrobat and functions as expected.

 

I initially thought that app requires a privilege escalation, so I created a Trusted Function following the requirements set out in the documentation.  I was also unable to get this to work when run with the "Run a Javascript" menu option, but this time my error had changed to:

Line: 86: Code: 24(0x18): trustedAlert is not a function

I was unable to solve this issue as well, and decided to ask for help here.

 

I would like to get app.alert running without having to deal with trusted functions for the sake of simplicity, but would be happy with anything that can solve my problem.

 

Images of code, failure, and both successes are provided. If more information is needed feel free to ask for it.

Thanks!

Correct answer Thom Parker

Hello,

I am trying to get this to run within the context of a 3D PDF Content Area. Right now, my goal is that when a user selects a part, what Adobe calls a node, then app.alert runs and displays some content to the user. For clarity I have attached both a sample 3D PDF, and a more complete example of my code. My issue is that using the right click context menu inside the 3D Content area and selecting "Run a Javascript", the console says that:

Line: 1: Code: 2(0x2): app is undefined
Line: 1: Code: 21(0x15): undefined is not an object

 

Does this mean that within the 3D PDF Javascript environment 'app' is not a usable API function? If so, can I get around this issue with a trusted function, or are those also not usable within this context? If trusted functions are not available, how can I get information to be accessible to a user without having them open the Javascript debugger and read from console.

 

The steps I have been using are as follows:

1. Open a 3D PDF, like shape.pdf that I provided, with Adobe Acrobat Pro

2. Right click within the 3D content area.

3. From the context menu that appears, select "Run a Javascript"

4. Browse to the Javascript that I want to run, in this case provided as Testing.txt, as uploading of .js files is forbidden.

5. Select a part from within the 3D PDF content.

6. Open the Javascript debugger to see that the code has failed out stating that 'app' is undefined.

 

I have also provided the file trustAlert.txt, which is my attempt to get a trusted function working. I have commented out the function call within Testing.txt as it is not immediately relevant to my primary question.

 

Let me know if you need any additional information.

Thanks.


So the 3D JavaScript model is completely different from the Acrobat JavaScript model. It lives in it's own world.  Has it's own objects and functions. 

I haven't written anything for the 3d model in years, so don't know if there is a popup message window, but you can access the Acrobat model from the 3D model through the "Host" object. 

 

Try this code:

 

host.app.alert("Hello World");

 

 

 

 

1 reply

PDF Automation Station
Adobe Expert
February 5, 2025

Folder level scripts run when Acrobat starts so success on startup is correct.  Scripts in the console run when you execute them so Success on console is correct.  Where exactly are you right-clicking to "run a javascript"?  app means the Acrobat application so if you're not running it from Acrobat or within a PDF viewer, then app is undefined and not an object if it hasn't been properly defined.

JHill700Author
New Participant
February 5, 2025

Hello,

The option is in the right click menu in Adobe Acrobat Pro. Attached is a photo of the menu I am talking about.

 

Thanks.

Thom Parker
Thom ParkerCorrect answer
Adobe Expert
February 5, 2025

Hello,

I am trying to get this to run within the context of a 3D PDF Content Area. Right now, my goal is that when a user selects a part, what Adobe calls a node, then app.alert runs and displays some content to the user. For clarity I have attached both a sample 3D PDF, and a more complete example of my code. My issue is that using the right click context menu inside the 3D Content area and selecting "Run a Javascript", the console says that:

Line: 1: Code: 2(0x2): app is undefined
Line: 1: Code: 21(0x15): undefined is not an object

 

Does this mean that within the 3D PDF Javascript environment 'app' is not a usable API function? If so, can I get around this issue with a trusted function, or are those also not usable within this context? If trusted functions are not available, how can I get information to be accessible to a user without having them open the Javascript debugger and read from console.

 

The steps I have been using are as follows:

1. Open a 3D PDF, like shape.pdf that I provided, with Adobe Acrobat Pro

2. Right click within the 3D content area.

3. From the context menu that appears, select "Run a Javascript"

4. Browse to the Javascript that I want to run, in this case provided as Testing.txt, as uploading of .js files is forbidden.

5. Select a part from within the 3D PDF content.

6. Open the Javascript debugger to see that the code has failed out stating that 'app' is undefined.

 

I have also provided the file trustAlert.txt, which is my attempt to get a trusted function working. I have commented out the function call within Testing.txt as it is not immediately relevant to my primary question.

 

Let me know if you need any additional information.

Thanks.


So the 3D JavaScript model is completely different from the Acrobat JavaScript model. It lives in it's own world.  Has it's own objects and functions. 

I haven't written anything for the 3d model in years, so don't know if there is a popup message window, but you can access the Acrobat model from the 3D model through the "Host" object. 

 

Try this code:

 

host.app.alert("Hello World");

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often