2 Replies Latest reply on Aug 29, 2011 5:46 AM by MarkWalsh

    Help with scripting a period in barcode between fields.

    abel@taproduce.com

      Good Morning,

      I need help scripting a barcode that has a period as a separator in between fields.

      I have 3 fields that I need all encoded in to one barcode and need a period as separators.

      EMPID

      FormName

      EMPSSN

       

      I need barcode to read as follows


      EMPID.FormName.EMPSSN

      546514.Harvest123.555284569

       

      I am very new to this and any help would be greatly appreciated.

        • 1. Re: Help with scripting a period in barcode between fields.
          MarkWalsh Level 4

          Are you just concatenating the 3 field values separated by a period?

           

           

          barcode = this.getField("EMPID").valueAsString + "." + this.getField("FormName").valueAsString + "." + this.getField("EMPSSN").valueAsString

          • 2. Re: Help with scripting a period in barcode between fields.
            try67 MVP & Adobe Community Professional

            When you go to the Barcode's Value tab and select "Custom calculation script", you get an empty template of how the barcode's value is calculated, which you can then fill-in with the names of the form fields. You can also edit the separator used between the values. I'm not sure the result is a valid barcode, strictly speaking, but it works. Here's the code I used:

             

            /* Customize: */
            function bMemberOf(strName, aStrNames)
            {
                for (var nMembIdx in aStrNames)
                {
                    if (strName == aStrNames[nMembIdx])
                        return true;
                }
                return false;
            }

             

            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 += "."; // I changed these two lines so the separator is a period instead of the default tab
                            strValues += ".";
                        }
                        if (oParam.bFieldNames)
                            strNames += strFieldName;
                        strValues += oParam.oDoc.getField(strFieldName).value;
                        bNeedTab = true;
                    }
                }
                if (oParam.bFieldNames)
                    return strNames + "\n" + strValues;
                else
                    return strValues;
            }

             

            try
            {
                if ( app.viewerVersion >= ADBE.PMD_Need_Version )
                    event.value = strTabDelimited({oDoc: this, aFields: ["EMPID", "FormName", "EMPSSN"], bFieldNames: true});
                else event.value = " ";
            }
            catch (e)
            {
                event.value = " ";
            }

            1 person found this helpful