Using a field from tablestart in another tablestart MS Word merge - ms-word

I am setting up a mail merge document with an object data source that has an object containing this structure:
id, firstName, lastName, address, donationText, donations
donations is an object itself with the following attributes:
donationType, donationAmount, donationDate
The mail merge document uses the mergefield TableStart and TableEnd to control the object data to use. For example, to use the firstName and lastName fields you have to use TableStart like this.
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{MEREFIELD TableEnd:person}
Since donations is an object, you have to use it using TableStart/TableEnd to access those fields.
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{MERGEFIELD TableStart:donation}
{MERGEFIELD donationType}
{MERGEFIELD TableEnd:donation}
{MERGEFIELD TableEnd:person}
You cannot use fields from person inside the TableStart/TableEnd for donation or vice-versa. What I need to do is to be able to check the donationType and if it is CHK or ECHECK then insert the donationText. I figured out you can use an IF statement like this:
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType}{MERGEFIELD TableEnd:donation}" = "CHK" "{MERGEFIELD donationText}" ""}
{IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType}{MERGEFIELD TableEnd:donation}" = "ECHECK" "{MERGEFIELD donationText}" ""}
{MERGEFIELD TableEnd:person}
I can get this statement to work if each IF statement is in a separate line. I need them to be in the same line to prevent blank lines from appearing. I also tried embedding one IF statement in the other but then neither of the IF statements work.
I am using MS Word 2010.

I figured out a solution. In order to embed one IF statement in the other, you have to add a newline before the embedded IF statement.
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType}{MERGEFIELD TableEnd:donation}" = "CHK" "{MERGEFIELD donationText}" {
IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType} {MERGEFIELD TableEnd:donation}" = "ECHECK" "{MERGEFIELD donationText}" ""}}
{MERGEFIELD TableEnd:person}
Adding the newline allows TableStart to work, otherwise you get an error since two TableStart tags cannot be in the same line.

Related

Extra line depending on input for mailing in Word

I have an Excel sheet with company names, contacts, address,... used for a mailing document in
Word. Ideally the address at the top should be:
{MERGEFIELD «company»}
to {MERGEFIELD «contact»}
{MERGEFIELD «street»}
{MERGEFIELD «city»}
But it's possible that there's no "contact" person known up there and then the address should be:
{MERGEFIELD «company»}
{MERGEFIELD «street»}
{MERGEFIELD «city»}
I wanted to use the "if" statement where it would be something like:
if ( {MERGEFIELD «contact»} <> "")
{MERGEFIELD «company»} + "\b" + "to "+ {MERGEFIELD «contact»}
else
{MERGEFIELD «company»}
But I can't get it working, I don't understand how Word splits the if-statement.
this works:
{ IF {MERGEFIELD «company»} <> "" {MERGEFIELD «contact»} {MERGEFIELD «company» }}
but if I add "to" it's not working anymore (and I don't know the newline tag neither)
Thanks for your time.
That's as simple as:
{MERGEFIELD «company»}{MERGEFIELD «contact» \b "¶
to "}
{MERGEFIELD «street»}
{MERGEFIELD «city»}
where the ¶ is a real paragraph break or line break.

Suppressing text and mail merge fields in Word based on another mail merge field

Our Student Information System (SIS) uses Word's mail merge functionality to create custom documents. I'm attempting to recreate a state-supplied form, and need some help.
In the document I've got six "sources": for each one there's a checkbox, a static text description, and a description field. I want to display the six as separate rows, but if the checkbox for that row is unchecked I don't want that row to display at all; I also don't want the checkbox to actually display here (it'll be displayed in a different place). The effect I'm looking for is a table where each row's visibility is controlled by the checkbox, and empty rows collapse.
When I create the document, the SIS creates a starter document with all of the fields referenced. After a little massaging, here's what I have:
{ MERGEFIELD TableStart:REV_DATA_ROOT/StudentDocument \*MERGEFORMAT}
{ MERGEFIELD #CogS1??TYPE=CHECKBOX} Source 1 { MERGEFIELD #CogS1Desc}
{ MERGEFIELD #CogS2??TYPE=CHECKBOX} Source 2 { MERGEFIELD #CogS2Desc}
{ MERGEFIELD #CogS3??TYPE=CHECKBOX} Source 3 { MERGEFIELD #CogS3Desc}
{ MERGEFIELD #CogS4??TYPE=CHECKBOX} Source 4 { MERGEFIELD #CogS4Desc}
{ MERGEFIELD #CogS5??TYPE=CHECKBOX} Source 5 { MERGEFIELD #CogS5Desc}
{ MERGEFIELD #CogS6??TYPE=CHECKBOX} Source 6 { MERGEFIELD #CogS6Desc}
{ MERGEFIELD TableEnd:REV_DATA_ROOT/StudentDocument \*MERGEFORMAT}
So if only the checkboxes for Source 1 and Source 5 were checked, only those two lines would display:
Source 1 Et ultrices neque ornare aenean euismod elementum nisi quis.
Source 5 Ultricies tristique nulla aliquet enim tortor at auctor urna.
(if the description wraps to the next line I'll play with the tabs and the hanging indent to mimic an actual table)
What I specifically want to avoid is having a blank line where unchecked checkboxes are. Is this possible?
Edit: When I print #CogS1, etc., by itself without setting the type to checkbox, it prints either True or False, so it should be possible to use this in an IF statement, but I'm not getting it to work. Also, in the original code above I had typed a single question mark just before "TYPE=CHECKBOX"; it's actually two question marks, and the code has been updated to reflect this.
To solve my problem I needed to use IF merge fields with a carriage return embedded in the "True" results; I also needed to have no carriage returns between the six IF merge fields. Based on the example I gave originally, here's what I ended up doing:
{IF {MERGEFIELD #CogS1} = "true" "Source 1: {MERGEFIELD #CogS1Desc}
"}{IF {MERGEFIELD #CogS2} = "true" "Source 2: {MERGEFIELD #CogS2Desc}
" ""}{IF {MERGEFIELD #CogS3} = "true" "Source 3: {MERGEFIELD #CogS3Desc}
" ""}{IF {MERGEFIELD #CogS4} = "true" "Source 4: {MERGEFIELD #CogS4Desc}
" ""}{IF {MERGEFIELD #CogS5} = "true" "Source 5: {MERGEFIELD #CogS5Desc}
" ""}{IF {MERGEFIELD #CogS6} = "true" "Source 6: {MERGEFIELD #CogS6Desc}
" ""}

Ignore special characters before match conditions

How can I write equivalent of following in mongo? I need to ignore some characters(spaces, hyphen) from a particular column before conditions are checked. For the sake of putting an example of mysql I am just removing space.
select * from TABLE
where REPLACE('name', ' ', '') = 'TEST'
So if name column has " T E S T" that should match.
You can try with $where operator in your query:
{$where: "this.name.replace(/[ -]/g,'') == 'TEST'"}
or:
{$where: "this.name.match(/T[ -]*E[ -]*S[ -]*T/)"}
or directly a $regex:
{name: /T[ -]*E[ -]*S[ -]*T/}
More info about $where $regex operators.

TRIM not works with lines and tabs of a xpath in PostgreSQL?

With this query
SELECT trim(title) FROM (
SELECT
unnest( xpath('//p[#class="secTitle1"]', xmlText )::varchar[] ) AS title
FROM t1
) as t2
and XML input text with lines and spaces,
<root>
...
<p class="x">
text text
text text
</p><p> ...</p>
...
</root>
The trim() have no effect (!). It is a PostgreSQL bug? How to apply fn:normalize-space() with the XPath? I need something like "WHERE title is not null"? (Oracle is simpler...) How to do this simple query with PostreSQL?
Workaround
I need a well-configured build-in function, not a workaround... But I need to work and to show results, so I am using regular expression...
SELECT id, TRIM(regexp_replace(tit, E'[\\n\\r\\t ]+', ' ', 'g')) AS tit
FROM (
SELECT
id, -- xpath returns array of 1, 2, or more strings
unnest( xpath('//p[#class="secTitle1"]', texto )::VARCHAR[] ) AS tit
FROM t
) AS tmp
So, a "only simple space trim" is not friendly, not util (!).
EDIT after #mu comment
I try
SELECT id, TRIM(tit, E'\\n\\r\\t') AS tit
and
SELECT id, TRIM(tit, '\n\r\t') AS tit
both NOT WORKs.
QUESTION REMAINS:
there are no TRIM-option or postgresql configuration to say to TRIM work as it is required?
can I use normalize-space() at xpath? How?
I am using PostgreSQL 9.1, need to upgrade?
It works in 9.2, and it works on 8.4 too.
postgres=# select trim(unnest(string_to_array(e'\t\tHello\n\t\tHello\n\t\tHello', e'\n')), e'\t');
btrim
-------
Hello
Hello
Hello
(3 rows)
your regexp replace any char \n or \r or \t, but trim working with string "\n\r\t". It has different meaning than you expect.

SSRS 2008 R2 Remove White Space if Null

I have a simple SQL Server 2008 R2 report with a textbox containing a few fields. I want to suppress the line if the value of a field is null. What would be the syntax for the expression?
So my fields are...
Name
AddressLine1
AddressLine2
AddressLine3
CityStateZip
and I have expressions like this...
=First(Fields!AddressLine2.Value, "dsPersonData")
I was trying the expression below but getting errors
=IIF(Fields!AddressLine2.Value, "",True,False)
In other words I was trying to set the visibility to false if the value was an empty string but I'm not sure what the syntax would be.
you can try
=IIF(First(Fields!AddressLine2.Value, "dsPersonData") is Nothing ,False,True)
Is easy to do this in the sql query, For example:
in SQL Server:
ISNULL(Name, '') as Name
ISNULL(AdressLine1, '') as AdressLine1
ISNULL(AdressLine2, '') as AdressLine2
ISNULL(AdressLine3, '') as AdressLine3
ISNULL(CityStateZip, '') as CityStateZip
and if you want to set the visibility to false:
=IIF(First(Fields!AddressLine2.Value, "dsPersonData") = "",False,True)