Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Custom file name to save the pdf using a button

Avatar

Level 3

Hello,

 

We can save a file where user need to give a file name

 

app.execMenuItem("SaveAs")

 

 

Now, I want a button, if user click then it will suggest user a pdf name based on the value given in the form. 

I am using the below code (based on this post) [on the button for click action]

 

var mySaveAs = app.trustedFunction(
   function(oDoc, cFlName) {
      app.beginPriv();
      
      try {
         oDoc.saveAs(cFlName);
      } catch (e) {
         app.alert("Error During Save");
      }

      app.endPriv();
   }
);

// Append the suffix "review" to the file name
var suggestedFileName = xfa.resolveNode("Num").rawValue + "_review";

mySaveAs(event.target, suggestedFileName + ".pdf");

 

 

But getting an error  

 

NotAllowedError: Security settings prevent access to this property or method.
App.trustedFunction:2:XFA:form1[0]:Page_1[0]:SBOR_Button_Subform[0]:Button_Save_All_Data[0]:click

 

 

Here, I used the trusted function's begin, and end privatization. But still why I am getting error, and how can I solve the error?

 

Update: I think I need to put the trusted function in my Adobe's JavaScript folder. However, this doesn't seems to be the best practice for my purpose, as I can't control my user's machine (and can't put the JS file on the Folder Level). Are there any other options to achieve the "Rename" functionality?

 

Thank you 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies