Skip to main content
Participant
Jun 14, 2019 6:05 PM UTC
Question

Split a long string (every other word) into multiple fields

Hi,

I'm trying to build an advance form that allows in-company ordering of products. The difficulty for most employees is to select the correct 'booking code' properly: which budget and which cost category.

For example: rubber stamps (part of the range of the office supply products) must be booked on B001(budget number) and 1234 (cost category). Short: B001.1234. Second example: pencils (again part of the  office supply products) must be booked on B001.1235. This product range is pretty large.

Our source for the correct booking codes is an Excel sheet: column 1 contains product names, column 2 the main category, column 3 the sub-category and column 4 the correct booking code. Example

rubber_stamps; office supplies;postal needs;B001.1234

pencils; office supplies;statiorary;B001.1235

etc.

The idea is to present employees with 3 pull down menu's: main category, subcategory and product.

For maintenance and update purposes, it would be great to import data into the form/these pull down menu's from a file that is easy to maintain and update.

Thus far, I have been able to read data from an attached CSV (the data.csv our controller can make /extract from an Excel sheet, send it to me and I can attach it to the adobe form). Current java code to get the data imported into the sheet works.

var oFile = this.getDataObjectContents("data.csv");

var cFile = util.stringFromStream(oFile, "utf-8");

this.getField("datafield").value = cFile

The result is a field that consists of a long string of text: rubber_stamps, office_supples,postal_needs,B001.1234 pencils,office_supples,stationary,B001.1235.

The problem I'm facing is how to split this data into 4 new data fields, so I can use the first 3 fields to populate the pull down menu's and - based on the 3rd selection (e.g. pencils), fill another field with the correct booking code B001.1235.

Any suggestions / help is very welcome. Thanks in advance.

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

try67
Community Expert
Community Expert
Jun 14, 2019 7:59 PM UTC

From your description it seems your file is not a CSV, but a semi-colon delimited text file. In that case it's much easier. Simply split using the semi-color as the delimiter...

Translate
Thom Parker
Community Expert
Community Expert
Jun 14, 2019 7:38 PM UTC

Correctly parsing a CSV file is non-trivial. You can't just split on a comma.

You'll file a complete solution here for both parsing the CSV and setting up the dropdown:

https://www.pdfscripting.com/public/ExcelAndAcrobat.cfm

But you'll need to purchase a membership, and learn a bit about scripting.

I could also built a custom solution for you. Contact me if you are interested.

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
Jun 14, 2019 6:12 PM UTC

You can use the string method split.

Translate
Participant
Jun 14, 2019 6:15 PM UTC

I tried, but I have no idea how to split it in such a way that I get the correct part of the string into a separate (hidden) field (that I can use then to populate the pull down menu's). Any coding examples? Thanks!

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 14, 2019 6:35 PM UTC

cFile.split(',') will return an array.

Translate