7 Replies Latest reply on Dec 14, 2015 12:25 PM by try67

    importIcon for toolbutton - Operation failed error

    rahulm24619544 Level 1

      hi:

      I am trying to create a button in tool bar using importIcon and am getting operation failed error. Here's my code -

      function helloWorld()

      {

           //Say Hello World

           app.alert("Hello World");

      }

       

      var CreateButton = app.trustedFunction( function() {

      app.beginPriv();

        // Create a document

         var myDoc = app.newDoc(1,1);

        var img = myDoc.importIcon("publishbutton", "/C/Development/tst.jpg", 0);

        var oIcon = util.iconStreamFromIcon(myDoc.getIcon("publishbutton"));

        

         app.addToolButton({

             cName: "helloWorldBtn", // A name for your button

          oIcon: oIcon,

             cExec: "helloWorld()", //Function to Call

             cTooltext: "Say Hello World" //The Help Text

      });

         myDoc.closeDoc(true);

         app.endPriv();

        });

       

      CreateButton();

       

       

      I get this error in console

      GeneralError: Operation failed.

      App.addToolButton:22:Folder-Level:App:PublishButton.js

       

      I myself created tst.jpg in that folder with simple text and saved as jpeg format from mspaint.

       

      to my surprise, when I comment the line

      oIcon: oIcon

       

      it works well creating a default icon.

       

      Please help.