Copy link to clipboard
Copied
Hi there! I am trying to create a custom Calculation script for a text box that concatenates many text fields from a separate page that has space for the details of 20 users. I have been able to use the script below to pull the details of each user and display them with the "|" character in between the data and a line break at the end of each user, so that the following user begins on the following line. This method though is very cumbersome and will require so many lines of code to build in the potential for all 20 users detail fields to be filled in. Is there a way that I can have a looping getField?
var u1name = this.getField("Internal - xUsers - Requested User 1").value;
var u1id = this.getField("Internal - xUsers - ID Number 1").value;
var u1pc = this.getField("Internal - xUsers - PC Name 1").value;
var u1email = this.getField("Internal - xUsers - Email Address 1").value;
var u1sub = this.getField("Internal - xUsers - Embedded Sub Company 1").value;
var u1 = u1name + " | " + u1id + " | " + u1pc + " | " + u1email + " | " + u1sub
var u2name = this.getField("Internal - xUsers - Requested User 2").value;
var u2id = this.getField("Internal - xUsers - ID Number 2").value;
var u2pc = this.getField("Internal - xUsers - PC Name 2").value;
var u2email = this.getField("Internal - xUsers - Email Address 2").value;
var u2sub = this.getField("Internal - xUsers - Embedded Sub Company 2").value;
var u2 = u2name + " | " + u2id + " | " + u2pc + " | " + u2email + " | " + u2sub
event.value = u1 + "\n" + u2 + "\n";
Also, the "Embedded Sub Company" field will not always be filled in, is there a way that I can make that not show the "|" at the end of the email address, if the field is empty?
Thank you for any and all help with this!
Copy link to clipboard
Copied
To use a loop, all the field names have to follow a common pattern. From the code you 've posted I'm assuming that the only difference is the number at the end?
Here's a loop:
event.value = "";
for(var i=1;i<NumGroups;i++)
{
var uname = this.getField("Internal - xUsers - Requested User 1").value;
var uid = this.getField("Internal - xUsers - ID Number 1").value;
var upc = this.getField("Internal - xUsers - PC Name 1").value;
var uemail = this.getField("Internal - xUsers - Email Address 1").value;
var usub = this.getField("Internal - xUsers - Embedded Sub Company 1").value;
var u = u1name + " | " + uid + " | " + upc + " | " + uemail;
if(usub != "")
u += " | " + u1sub;
event.value += u + "\n";
}
Copy link to clipboard
Copied
To use a loop, all the field names have to follow a common pattern. From the code you 've posted I'm assuming that the only difference is the number at the end?
Here's a loop:
event.value = "";
for(var i=1;i<NumGroups;i++)
{
var uname = this.getField("Internal - xUsers - Requested User 1").value;
var uid = this.getField("Internal - xUsers - ID Number 1").value;
var upc = this.getField("Internal - xUsers - PC Name 1").value;
var uemail = this.getField("Internal - xUsers - Email Address 1").value;
var usub = this.getField("Internal - xUsers - Embedded Sub Company 1").value;
var u = u1name + " | " + uid + " | " + upc + " | " + uemail;
if(usub != "")
u += " | " + u1sub;
event.value += u + "\n";
}
Copy link to clipboard
Copied
Thank you kindly for the response! Using the code that you suggested, with a couple of tweaks (see below), I was able to get it to work, but have a further question. How could I make the "|" seperator only show if the name field is filled in.
Name 1 | UserID 1 | PC Name 1 | Email 1
Name 2 | UserID 2 | PC Name 2 | Email 2
| | | <----- Do not want the separators to show if the name field is left blank.
event.value = "";
for(var i=1;i<5;i++)
{
var uname = this.getField("Internal - xUsers - Requested User " + i).value;
var uid = this.getField("Internal - xUsers - ID Number " + i).value;
var upc = this.getField("Internal - xUsers - PC Name " + i).value;
var uemail = this.getField("Internal - xUsers - Email Address " + i).value;
var usub = this.getField("Internal - xUsers - Embedded Sub Company " + i).value;
var u = uname + " | " + uid + " | " + upc + " | " + uemail;
if(usub != "")
u += " | " + usub;
event.value += u + "\n";
}
Copy link to clipboard
Copied
You can do that you can use an array, like this:
var values = [];
var uname = this.getField("Internal - xUsers - Requested User " + i).valueAsString;
if (uname!="") values.push(uname);
var uid = this.getField("Internal - xUsers - ID Number " + i).valueAsString;
if (uid!="") values.push(uid);
var upc = this.getField("Internal - xUsers - PC Name " + i).valueAsString;
if (upc!="") values.push(upc);
var uemail = this.getField("Internal - xUsers - Email Address " + i).valueAsString;
if (uemail!="") values.push(uemail);
var usub = this.getField("Internal - xUsers - Embedded Sub Company " + i).valueAsString;
if (usub!="") values.push(usub);
var u = values.join("|");
Copy link to clipboard
Copied
U6 Rajib Hossain
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more