Skip to main content
Participant
September 5, 2023
Question

Add pdf button not working

  • September 5, 2023
  • 1 reply
  • 1598 views
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
  }
}
This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
September 5, 2023

Any error message?

Participant
September 5, 2023

here is the updated code , no error nothing showing ,and after click on add pdf still not happenig anythig @Bernd Alheit 

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 = oDlg.description.elements[3].elements[2]; // Access the "Add PDF" button directly

    addPdfButton.onClick = 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
  }
}
Bernd Alheit
Community Expert
Community Expert
September 5, 2023

Where does you use this functions?