I'm having issues regarding this custom barcode calculation. The initial problem was that leading zero's were dropping from various fields. Now, the zero's are fine, however the fields i have listed with the custom script are duplicating and I'm missing some fields. Please see the script below. Any help or advice would be much appreciated. I'm a newbie.
This is the code that I currently have. For some reason, it is doubling the output of the fields that I edited.
/* Customize: */
function bMemberOf(strName, aStrNames)
{
for (var nMembIdx in aStrNames)
{
if (strName == aStrNames[nMembIdx])
return true;
}
return false;
} // end bMemberOf
function strTabDelimited(oParam)
{
var bNeedTab = false;
var strNames = "";
var strValues = "";
for (var i = 0; i < oParam.oDoc.numFields; ++i)
{
var strFieldName = oParam.oDoc.getNthFieldName(i);
if ((null == oParam.aFields || bMemberOf(strFieldName, oParam.aFields))
&& (null == oParam.strXclField || strFieldName != oParam.strXclField)
&& (oParam.oDoc.getField(strFieldName).type != "button"))
{
if (bNeedTab)
{
if (oParam.bFieldNames)
strNames += "\t";
strValues += "\t";
}
if (oParam.bFieldNames)
strNames += strFieldName;
// ALL OF THESE FIELDS ARE BEING DUPLICATED FOR SOME REASON...CAN YOU TELL ME WHY?
if(strFieldName == '001_SSN') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '009_Mailing Address Zip Code') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '015_Home Address Zip') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '017_Home Phone') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '018_Mobile Phone') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '019_Home Office Phone') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '020_Work Phone') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '021_Other Phone') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
}
if(strFieldName == '022_Fax Phone') {
strValues += oParam.oDoc.getField(strFieldName).valueAsString;
} else {
strValues += oParam.oDoc.getField(strFieldName).value;
}
bNeedTab = true;
}
}
if (oParam.bFieldNames)
return strNames + "\n" + strValues;
else
return strValues;
} // end strTabDelimited
try
{
if ( app.viewerVersion >= ADBE.PMD_Need_Version )
// enter field names between brackets for aFields parameter
event.value = strTabDelimited({oDoc: this, aFields: ['001_SSN', '002_First_Name', '003_Last Name', '004_Middle Name',
'005_Mailing Address Street 1', '006_Mailing Address Street 2', '007_Mailing Address City', '008_Mailing Address State',
'009_Mailing Address Zip Code', '010_Country Code', '011_Home Address Street 1', '012_Home Address Street 2', '013_Home Address City',
'014_Home Address State', '015_Home Address Zip', '016_Home Address Country Code', '017_Home Phone',
'018_Mobile Phone', '019_Home Office Phone', '020_Work Phone', '021_Other Phone', '022_Fax Phone', '023_Email Address', '024_Marital Status', '025_Birth Date',
'026_Gender', '027_Ethnicity', '028_Disability_Type', '029_Disabled Veteran', '030_Accomodation Needed', '031_Military Status', '032_Race Ethnicity', '033_Preferred Name',
'034_Suffix'], bFieldNames: true});
else event.value = " ";
}
catch (e)
{
event.value = " ";
}
console.println('result:\n\n ' + event.value); // display result
You need a series of 'if then else if then' statements or write a compound statement for the if statement to include all the fields you want to use the 'valueAsString' property for. You will be using the OR logical operator.
George Kaiser