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

Custom dialog initialisation help please...

New Here ,
Dec 29, 2020 Dec 29, 2020

Copy link to clipboard

Copied

Hi there,

I'm having trouble with passing the information returned from a app.browseForDoc within a custom dialog. The app.browseForDoc is assigned to a button, which triggers ok, however I'm encountering 'undefined' when I try to get the filename or file path of the file selected.

I think it's the way I'm initialising the variable used to store and return the info from the app.browseForDoc. I've tried initialising 'baseFile' in a few different ways but I'm still having problems.

Please can someone help me.

Thanks in advance.

 

Here's my code so far:

 

var oDlg = {
	strName: "", initialize: function(dialog) { 
	    dialog.load({"usnm":this.strName}, this.baseFile = ""); },
        commit: function(dialog) { 
              var data = dialog.store();
              this.strName = data[ "usnm"];
    	      var baseFile = dialog.store();
              this.baseFile = data[ "baseFile"];
      	  },
		butn: app.trustedFunction(function(dialog) {
        	app.beginPriv();
        	  var baseFile = app.browseForDoc();
    	    app.endPriv();
			}),
        description: { name: "Test Dialog", elements: [
        	{ type: "view", elements: [
    	    	{ type: "button", item_id: "butn", name: "Select 1st pdf"},
        		{ name: "Enter no. of files:", type: "static_text", },
				{ item_id: "usnm", type: "edit_text", char_width: 15 },
				{ type: "ok_cancel", },
			] },
		] }
};

// Dialog Activation 
oDlg.strName = "765"; // Enter a default value of files to process 
if( "ok" == app.execDialog(oDlg)) { 
    console.println("Number of files to process: " + oDlg.strName);
    console.println("Selected base file: " + oDlg.baseFile);  
}

 

TOPICS
Acrobat SDK and JavaScript , Mac

Views

388

Translate

Translate

Report

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 ,
Dec 30, 2020 Dec 30, 2020

Copy link to clipboard

Copied

The trusted function can't be a part of the dialog object. You have to create it separately and place it inside of a .js file in the application's Javascripts folder, and then just call it from the dialog. Also, it needs to return a value if you want to use it later on in your code.

Votes

Translate

Translate

Report

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 ,
Dec 30, 2020 Dec 30, 2020

Copy link to clipboard

Copied

Also, baseFile is a variable, not a field, so you can't assign a value to it like this:

this.baseFile = data[ "baseFile"];

 

You need to assign to it the return value of the call to the trusted function that calls browseForDoc.

Votes

Translate

Translate

Report

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
New Here ,
Dec 30, 2020 Dec 30, 2020

Copy link to clipboard

Copied

Hi Try67,

Thanks for all the help.

If I'm aiming for the finished item to be a custom menu item can the trusted function, and code for the rest of the process, be in the same .js file or does the trusted function need to be separate?

Also, I've created a custom menu item in the past and wondered is there a way the code for the .js can be edited and any changes carried through to Acrobat without having to restart the app?

Thanks again for the help 🙂

Votes

Translate

Translate

Report

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 ,
Dec 30, 2020 Dec 30, 2020

Copy link to clipboard

Copied

If you put it all in a folder-level script that can work, but you would have to place it in all in a function, or it will run at the moment the application opens.

I would still recommend splitting the trusted function from the rest of it.

 

And no, after each change to the .js file you must restart the application for it to take effect.

Votes

Translate

Translate

Report

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
New Here ,
Dec 30, 2020 Dec 30, 2020

Copy link to clipboard

Copied

LATEST

Thanks again for the help and clarification on the best approach.

I'll do as you've suggested and split out the trusted function.

Cheers!

Votes

Translate

Translate

Report

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