2 Replies Latest reply on Oct 3, 2012 12:21 PM by MaxCO2012

    Syntax for a Custom Boolean Function.

    MaxCO2012 Level 1

      Can someone please help me with the syntax for a custom boolean function in JS?

       

      I am trying to pass an argument to a function and, instead of having that function test the condition and set a variable to "true" or "false", I want the function itself to be the boolean variable. My code currently looks like this:

       

      var VerifyFileExists = app.trustedFunction( function(File_Name)

      {

      app.beginPriv();

           global.FileExists = true;

           try{

                oDoc = app.openDoc({

                     cPath: File_Name,

                     bHidden: true

           })

                FileExists = true

                oDoc.closeDoc();

           }catch(e){

                FileExists = false

           }

      app.endPriv();

      });

        • 1. Re: Syntax for a Custom Boolean Function.
          gkaiseril MVP & Adobe Community Professional

          You could return the "FileExists" value.

           

          var VerifyFileExists = app.trustedFunction( function(File_Name)

          {

          app.beginPriv();

               global.FileExists = true;

               try{

                    oDoc = app.openDoc({

                         cPath: File_Name,

                         bHidden: true

               })

                    FileExists = true

                    oDoc.closeDoc();

               }catch(e){

                    FileExists = false

               }

          app.endPriv();

          return FileExists;

          });

          • 2. Re: Syntax for a Custom Boolean Function.
            MaxCO2012 Level 1

            Yes, that's what I'm doing now. But it causes an additional line of code because I have to first pass the File_Name to the function and then check the value of FileExists, like this:

             

            VerifyFileExists("Allowance Schedule.pdf");

                 if (FileExists == true) myDoc.insertPages({nPage:myDoc.numPages-1, cPath:"Allowance Schedule.pdf"});

             

            What I want to do is more like:

             

            If(VerifyFileExists("Allowance Schedule.pdf") myDoc...

             

            Thanks!