EricC Posted September 17, 2014 Share Posted September 17, 2014 I have a Marcom store with a multi-line text box. The user will enter data as follows (into a single text box): 13-103 | Calculus I | 9-10 | W 10-212 | English 1102 | 11-12 | W 11-109 | Statistics | 12-1 | W 19-115 | Project Management | 8-9 | F 17-206 | Chemistry 2 | 8-9 | S The user is instructed to enter a pipe symbol as a delimiter. So here's what I need to do: 1. Write a rule that will read the entire contents of that multi-line text box into an object(?) or array(?) 2. Use the FusionPro table object to create a new instance of a 4 column table, and populate the entire table with the data above The number of rows will vary, but it will always have 4 columns. I was able to get this to work if the data is in an external data file (using ExternalDataFileEx and a for loop). But I'm having trouble figuring out how to read in the data if it's in a multi-line text box (not an external data file). Is there a FusionPro function that does this? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 17, 2014 Share Posted September 17, 2014 Did you do what Support suggested, and typeset the value of that field onto a text frame (with a rule returning the field with the "Treat returned strings as tagged text" box checked)? Without seeing that, and knowing exactly what MarcomCentral is putting out into the generated data file for that field, it's hard to know how to parse that out in a rule. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 17, 2014 Share Posted September 17, 2014 Or, you could try asking your MarcomCentral-specific question on the MarcomCentral forum, where the people who might know exactly what MarcomCentral puts into the data file for a multi-line field tend to hang out. Quote Link to comment Share on other sites More sharing options...
step Posted September 17, 2014 Share Posted September 17, 2014 (edited) Is something like this what you're looking for? var data = Field("Your Multi-line Field"); data = data.replace(/[\n\r]/g,'<br>'); var row = data.split("<br>"); var myTable = new FPTable; myTable.AddColumns(4800, 4800, 4800, 4800); myTable.AddRows(row.length); for (var i=0; i<row.length; i++) { var column = row[i].split("|"); myTable.Rows[i].Cells[0].SetBorders("Thin","Black","Top","Bottom","Right","Left"); myTable.Rows[i].CopyCells(0,1,2,3); myTable.Rows[i].Cells[0].HAlign = "Center"; myTable.Rows[i].SetContents(column[0],column[1],column[2],column[3]); } return myTable.MakeTags(); Edited September 18, 2014 by step typo Quote Link to comment Share on other sites More sharing options...
EricC Posted September 17, 2014 Author Share Posted September 17, 2014 Hi Dan, Thanks for the quick reply. I'm not sure I understood what "typeset the value of that field onto a text frame (have a rule return the field)" meant. Does this mean in my template I can draw a FusionPro text box, hard-code some (static) text in there, and then write a rule to modify it? I'm confused? (Also, I realized that reading in the text is only half of the battle - after figuring out how to do this I'll probably need help writing the loop that formats the table. So that's why I posted the same question here in the forum). Quote Link to comment Share on other sites More sharing options...
EricC Posted September 17, 2014 Author Share Posted September 17, 2014 Stephen, How are you able to think so fast?! ;-) That's EXACTLY what I needed. Thank you thank you. In the second line there was a minor slip-up: test = test.replace(/[\n\r]/g,'<br>'); should be ... test = data.replace(/[\n\r]/g,'<br>'); Question ... so is the variable 'data' an array? (When you read in a multi-line text box I guess FusionPro automatically makes this an array?) Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 17, 2014 Share Posted September 17, 2014 (edited) I'm not sure I understood what "typeset the value of that field onto a text frame (have a rule return the field)" meant. Does this mean in my template I can draw a FusionPro text box, hard-code some (static) text in there, and then write a rule to modify it? No, hard-coding some static text doesn't help us at all. The whole problem, the bit of information that's still missing here, even after all the screenshots of what the web form looks like that you sent, is that we need to know exactly what the content of that data field is. We need to know exactly what MarcomCentral is putting in there so that we can know exactly how to parse it out into separate lines. What it means is this: Create a JavaScript rule with the "Treat returned strings as tagged text" box checked, and this syntax: return Field("Your Multi-line Field"); // your field name here Give that rule a name and click OK to save it. Then create a text frame, open up the Text Editor, select the name of the rule you just created in the Variable drop-down list and click Insert. Then re-collect the job and compose it on MarcomCentral. The output should now show exactly what MarcomCentral is generating for that multi-line field. Once we know that, and we see how it delimits the separate lines of text entered by the user, then we will know what to write in our rule. Does that make sense? I'm confused? Yes. Although I'm still trying to remedy that. Also, I realized that reading in the text is only half of the battle - after figuring out how to do this I'll probably need help writing the loop that formats the table. So that's why I posted the same question here in the forum). If you didn't understand what Support instructed you to do, I would have expected you to ask Support for clarification, rather than ignoring their instructions completely and starting over again here on the forum. We (PTI) are trying to help, but you have to do a little bit to help us help you. Also, this is absolutely a MarcomCentral-specific question. Yes, you have to write the rule in FusionPro, but (again) what you have to do in there depends on what MarcomCentral puts into the data file, which could be different than what some other web-to-print system might put into the data file for a similar kind of multi-line field. Therefore, the rule you have to write is indeed specific to MarcomCentral. So if you do need to ask a question like this here on the forum, it should be asked in the MCC-specific subforum. Now, having said all of that, it seems that our friend step already knows that MarcomCentral outputs <br> tags to delimit lines from a multi-line edit web field. That's what we have been trying to figure out. Question ... so is the variable 'data' an array? (When you read in a multi-line text box I guess FusionPro automatically makes this an array?) No, the variable 'data' is a String value, which contains the result of the call to the Field function, i.e. the contents of the data field from the data file. The call to the String.split function returns an Array, which is assigned to a different variable. Again, FusionPro doesn't "automatically" do anything with a multi-line text box. It doesn't know about a multi-line text box, nor anything about what kind of web application may have created the data file, nor what kinds of controls it may have presented to the user. All that FusionPro has to go on, all that it can possibly go on, is what's in the data file that it's processing. Edited September 17, 2014 by Dan Korn Quote Link to comment Share on other sites More sharing options...
step Posted September 18, 2014 Share Posted September 18, 2014 Stephen, How are you able to think so fast?! ;-) That's EXACTLY what I needed. Thank you thank you. In the second line there was a minor slip-up: test = test.replace(/[\n\r]/g,'<br>'); should be ... test = data.replace(/[\n\r]/g,'<br>'); Question ... so is the variable 'data' an array? (When you read in a multi-line text box I guess FusionPro automatically makes this an array?) Sorry, I had originally named that variable "test" but forgot to change it everywhere else. I went back and edited the code in my first post. Reading in a multi-line text box does not create an array but splitting it does. So I split the string in that multiple line field by breaks ("<br>") in order to split the field into an array of rows. Quote Link to comment Share on other sites More sharing options...
EricC Posted September 19, 2014 Author Share Posted September 19, 2014 Dan, I appreciate the thorough reply. You are right - I should have continued working with support directly. My post on the forum does not mean support wasn't helpful. I just started realizing that was (in my mind) originally a small puzzle was turning into something more complex, so I thought I'd use the forum to see if I could get clarification. Your explanation above is clear to me, and next time I will post Marcom-specific questions in that forum. Step, thanks for your help and for the follow-up. Have a great weekend guys! Quote Link to comment Share on other sites More sharing options...
EricC Posted September 30, 2014 Author Share Posted September 30, 2014 This rule works perfectly on my desktop but when I upload it to Marcom, the rule "breaks" :-( I'm going to contact PTI support to see if they can help me figure this out. If I can get this fixed I will post the solution in the Marcom forum. Quote Link to comment Share on other sites More sharing options...
sandigcustomprinters.com Posted October 26, 2015 Share Posted October 26, 2015 I am looking to do similar task: split a multi-line text field into an array based on the line break as the delimiter. I have tried: var data = Field("BenefitsList"); var eachLine = data.split(/\n/g); and other regular expressions to no avail. Does anyone know how to split on a line break in a multi-line text field? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.