Skip to main content
Participant
December 29, 2020
Question

Custom dialog initialisation help please...

  • December 29, 2020
  • 1 reply
  • 572 views

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

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
December 30, 2020

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.

try67
Community Expert
Community Expert
December 30, 2020

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.

Nick5E79Author
Participant
December 30, 2020

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 🙂