How to remove extra carriage return on a generated text file in Appian
0085117,000011.55,000011.55CRLF0052514,000035.00,000035.00CRLFCRLF
Discussion posts and replies are publicly visible
Is this file generated with the Text Doc from Template node?
load( /*This expression should be 100% - 9-19-19 */ local!lines:if( rule!APN_isEmpty(ri!DIRDEP_LINES), {"NO DATA,000000.00,000000.00" }, { a!forEach( /*replace test array with rule input*/ items: ri!DIRDEP_LINES, expression: { /* Position 1-7 (7) CCDDEP_ACCOUNT_NO */ substitute(padleft(trim(fv!item.caseId),7)," ",0) & "," & /* Position 9-17 (9) CCDDEP_AMT */ if(rule!APN_isEmpty(fv!item.paymentAmt), substitute(padleft(trim(fv!item.paymentAmt),9)," ",0), substitute(padleft(trim(fixed(fv!item.paymentAmt)),9)," ",0) ) & "," & /* Position 19-27 (9) CCDDEP_AMTR */ if(rule!APN_isEmpty(fv!item.paymentAmt), substitute(padleft(trim(fv!item.paymentAmt),9)," ",0), substitute(padleft(trim(fixed(fv!item.paymentAmt)),9)," ",0) ) } ) }), joinarray(stripwith(local!lines,";"),chr(13)&CHR(10)) )
The code looks like this.
The text file is generated dynamically when the process model runs.
I would start with removing the curly brackets in lines 8, 12, 33, 36. This turns a simple list of strings into a list of list of a single string.
Just to confirm, that expression will return a text value - but to convert the result it into a document, you must be running it through something such as the Text Doc From Template smart service? E.g. my first step would be to confirm the template itself does not contain the extra line break, if this is the case.
I'm also surprised the chr() function is working for you as the documented function we typically use for this in Appian is fn!char().
I think I found the template. Please see attached image
Is the expression above inserting text into the replacement field ###line###? Because if you're doing that but then not passing in any text for ###trailer### then you will automatically have an extra carriage return at the end of your text file, no matter what. Can you post a screenshot of the configuration of the text from template node?
Yes that is the node. If you are populating ###line### with your rows, you may be able to nix the ###trailer### placeholder in the template. You can see what is loaded into those within the smart service Setup tab:
The template is used by other processes aswell. Looking at the node, I found that only the header is user from the template for that file.
nicholaso0002 said:Looking at the node, I found that only the header is user from the template for that file
This will be the cause of your extra carriage return(s), given that the first two lines in the template (as evidenced in your screenshot earlier) have hardcoded carriage returns at the ends of the rows, which will be unaffected by the Appian generation. You will need to migrate to a different template for this process, preferably one where your template file only contains the replacement field(s) needed.