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

Community Beginner ,
Jun 14, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

111

Likes

Translate

Translate

Report

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

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

Community Beginner ,
Jun 14, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

112

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 14, 2019 0
Adobe Community Professional ,
Jun 14, 2019

Copy link to clipboard

Copied

You can use the string method split.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 14, 2019 0
Community Beginner ,
Jun 14, 2019

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 14, 2019 0
Adobe Community Professional ,
Jun 14, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 14, 2019 0
Adobe Community Professional ,
Jun 14, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 14, 2019 0
try67 LATEST
Most Valuable Participant ,
Jun 14, 2019

Copy link to clipboard

Copied

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...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 14, 2019 0