Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

script writing help, multiple text boxes and if/than parameter

Community Beginner ,
Jul 03, 2023 Jul 03, 2023

the below script breaks every time at the this.getfield command. Rank and Abbreviated rank are list boxes. I am trying to run this InDesign and willing to push it to acrobat but dont know if that would work either.

 

// Get references to the required fields
var rankField = this.getField("Rank");
var firstField = this.getField("First");
var lastField = this.getField("Last");
var dutyTitleField = this.getField("Duty Title");
var unitField = this.getField("Unit");
var inputField = this.getField("input");
var decField = this.getField("dec");
var abbreviatedRankField = this.getField("Abbreviated Rank");

// Check the values of the checkboxes
var longCheckbox = this.getField("long").value;
var shortCheckbox = this.getField("short").value;

// Get the values from the input fields
var rank = rankField.valueAsString;
var first = firstField.value;
var last = lastField.value;
var dutyTitle = dutyTitleField.value;
var unit = unitField.value;
var input = inputField.value;
var abbreviatedRank = abbreviatedRankField.valueAsString;

// Build the output based on the checkbox values
var output = "";
if (longCheckbox === "Yes") {
output = rank + " " + first + " " + last + " distinguished " + (firstField.value === "female" ? "herself" : "himself") + " by meritorious service as " + dutyTitle + ", " + unit + ".";
} else if (shortCheckbox === "Yes") {
output = rank + " " + first + " " + last + " distinguished " + (firstField.value === "female" ? "herself" : "himself") + " by meritorious service while assigned to " + unit + ".";
}

// Set the value of the 'dec' field
decField.value = output;

// Build and set the closing phrase
var closingPhrase = "The distinctive accomplishments of " + abbreviatedRank + " " + last + " reflects credit upon " + (firstField.value === "female" ? "herself" : "himself") + " and the United States Air Force.";
this.getField("closingPhrase").value = closingPhrase;

TOPICS
Bug , Experiment , How to
801
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2023 Jul 03, 2023

Where is the definition of the getField method you are using? What is the value of the this object? This seems to be an incomplete set of code. Please share the complete one, only then will we be able to troubleshoot it.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 04, 2023 Jul 04, 2023

All references are inside the current document. all values are text fields besides 2 check boxes. The current code that works in acrobat is attached. I needed the added functionality of being able to have justified alignment set in the space so I wanted to use InDesign.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2023 Jul 04, 2023

Hi @Daniel308633812s5g , Your code looks like it’s using the Acrobat API—there is no getField() method in the InDesign API.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2023 Jul 04, 2023

An InDesign document has a formFields property, which would be a collection of all formFields in a document.

This would get the active document’s form fields:

 

var ff = app.activeDocument.formFields.everyItem().getElements();

for (var i = 0; i < ff.length; i++){
    $.writeln(ff[i].name)
    //returns the name of every form field in the active document
}; 

 

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#FormField.html#d1e127934

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 04, 2023 Jul 04, 2023

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2023 Jul 04, 2023

You can't use the API from one app in a different app. Each one does different things, in different ways. This is for the Acrobat API only. But you can't justify text in a fillable PDF field, not by any trick; whether you made it in InDesign doesn't give more power to the PDF fields. However, it's normal to design the form in InDesign then export to PDF.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 04, 2023 Jul 04, 2023

Thank you! sounds like I have to leave instructions for people to select the text frame, ctrl+E and select justified to get the result they need to view.. not what i wanted but seems to be the only option I have with limited experience and wanting this to be able to be a mass distrobution.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2023 Jul 04, 2023

If you attempt a mass distribution you may have many other issues. Can you FORCE people to use suitable software - that is, Acrobat Reader on Mac or Windows? When they already have an app that can read PDF? And will you tell people on iOS and Android that they are out of luck? I think you're reaching beyond what is feasible. If you want to give people a precisely formatted PDF, you need to generate them on a server and deliver them - a very different kind of programming.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 04, 2023 Jul 04, 2023
LATEST

every one of our computers are equiped with acroboat pro 2020. im testing it on myself in that domain before pushing it up. trying to eliminate the annoying part of writing decorations/medals and it has to generate a pdf for download to preview if you have reached appropriate guidelines

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines