i want when i click on Add Pdf button it should open a file explorer and open we can select pdf file and then i can use that pdf file anywhere .. Here is my code pls check and help me
function showUploadDialog() {
// Dialog Definition
var oDlg = {
usnm: {
flnm: "",
vers: "",
lfnu: "",
lccn: "",
},
initialize: function (dialog) {
dialog.load(this.usnm);
},
commit: function (dialog) {
var data = dialog.store();
this.usnm.flnm = data.flnm;
this.usnm.vers = data.vers;
this.usnm.lfnu = data.lfnu;
this.usnm.lccn = data.lccn;
},
description: {
name: "Test Dialog",
elements: [
{
type: "view",
elements: [
{ name: "Filename:", type: "static_text" },
{ item_id: "flnm", type: "edit_text", char_width: 30 },
],
},
{
type: "view",
elements: [
{ name: "Version:", type: "static_text" },
{ item_id: "vers", type: "edit_text", char_width: 30 },
],
},
{
type: "view",
elements: [
{ name: "LegalEdge File Number:", type: "static_text" },
{ item_id: "lfnu", type: "edit_text", char_width: 30 },
],
},
{
type: "view",
elements: [
{ name: "LegalEdge Court Case Number:", type: "static_text" },
{ item_id: "lccn", type: "edit_text", char_width: 30 },
{ type: "button", name: "Add PDF", item_id: "add_pdf_button" },
{ type: "ok_cancel" },
],
},
],
},
};
// Dialog Activation
oDlg.usnm.flnm = "Larry";
oDlg.usnm.vers = "1.0";
oDlg.usnm.lfnu = "Sample";
oDlg.usnm.lccn = "Sample2";
var response = app.execDialog(oDlg);
// Attach a click event listener to the "Add PDF" button
if (response === "ok") {
var addPdfButton = this.getField("add_pdf_button"); // Access the "Add PDF" button directly
addPdfButton.setAction("MouseUp", function () {
addPdfButtonClicked = true; // Set the flag
openFileExplorerForPdf(); // Call the function to open the file explorer
});
}
}
// Define a global variable to indicate whether the "Add PDF" button was clicked
var addPdfButtonClicked = false;
// Function to open the file explorer dialog
function openFileExplorerForPdf() {
if (addPdfButtonClicked) {
var cAttachmentPath = app.browseForDoc();
if (cAttachmentPath) {
var attachmentCounter = 0;
attachmentCounter++;
var fileAttachment = this.addAnnot({
page: 0,
type: "FileAttachment",
rect: [100, 100, 200, 200],
contents: "Attached file " + attachmentCounter,
cAttachmentPath: cAttachmentPath,
});
}
addPdfButtonClicked = false; // Reset the flag
}
}