This is a migrated thread and some comments may be shown as answers.

Mail Merge field that might not be needed

8 Answers 144 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 03 Dec 2013, 07:05 AM

Hi,


I am using Mail Merge fields to write address on an envelope.  Here is an example:

John Smith

125 Main St

Toronto, ON M2R 3B7

Canada



Sometimes there could be 2 lines for the address, for example:

John Smith

5th Floor

125 Main St

Toronto, ON M2R 3B7

Canada



Below is how I have setup document in RichTextBox.

{MERGEFIELD FullName}

{MERGEFIELD Address1}

{MERGEFIELD Address2}

{MERGEFIELD City}, {MERGEFIELD Province} {MERGEFIELD PostalCode}

{MERGEFIELD Country}

But if Address2 is empty, I don't want to have an empty line. I need to setup Address2 mail merge field in such a way, so that if it is empty, it does not take up the line and City/Province/PostalCode displayed on the 3rd line.



Anyone can suggest how to achieve this either through the template or through the backend?




8 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 06 Dec 2013, 09:27 AM
Hello,

Please find attached a sample project demonstrating how you can achieve the desired result using the TextAfterIfNotEmpty property of merge fields. For this purpose the fields are added on a single line and a line break is added to the mentioned property. If you preview the results of the mail merge and change the current item you can see how this behaves.

I hope this is helpful!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Michael
Top achievements
Rank 1
answered on 09 Dec 2013, 12:43 AM

Hi,



Thank you for this example.  The result is exactly what I am looking for.  However, it looks like you have hardcoded the TextAfterIfNotEmpty property into a template with some weird character TextAfterIfNotEmpty="¬".  What is this character?



In my program, user can modify the template.  I want to give this option to the user.  I noticed that once I switch to "Show All Fields Codes" mode, it looks like this:

{MERGEFIELD Address1 \f

}{MERGEFIELD Address2 \f

}{MERGEFIELD Address3 \f

}Text after fields


When I add field myself and add '\f' to it, this flag is not saved.



I also tried adding button to the ribbon bar and On Click inserting special character into the field using editor.Insert("¬");. But now I can see the new line, but no \f.  So I can see that I am missing something...



Maybe I misunderstood your example, can you clarify how users can set TextAfterIfNotEmpty property of the field themselves?



Thank you,

Michael



0
Petya
Telerik team
answered on 11 Dec 2013, 02:47 PM
Hello Michael,

You can insert a merge field with its TextAfterIfNotEmpty property set in the following manner:
this.editor.InsertField(new MergeField() { TextAfterIfNotEmpty = "¬", PropertyPath = "Address1" }, FieldDisplayMode.DisplayName);

The symbol used in this approach is the one which is interpreted as line break from RadRichTextBox. As to the flag, it indicates that the TextAfterIfNotEmpty property is set and following it is its content. 

As to allowing users to insert their fields in the same manner from RadRichTextBox's UI, you could subscribe to the CommandExecuting event of RadRichTextBox and handle the insertion of merge fields like this:
if (e.Command is InsertFieldCommand)
{
    MergeField field = (e.CommandParameter as MergeField);
    if (field != null)
    {
        if (field.PropertyPath.StartsWith("Address"))
        {
            e.Cancel = true;
            this.editor.InsertField(new MergeField() { TextAfterIfNotEmpty = "¬", PropertyPath = "Address1" }, FieldDisplayMode.Code);
        }
    }
}

Please note that this solution is merely a workaround as the scenario is currently not natively supported by RadRichTextBox. Such requirements will be supported once IF fields, which are already in our to-do list, are implemented.

Let me know if you have further questions.

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Michael
Top achievements
Rank 1
answered on 20 Aug 2014, 10:57 PM
Hi,

Have you implemented the IF option the merged field?  If you did, can you show some example here?

Michael
0
Petya
Telerik team
answered on 21 Aug 2014, 11:18 AM
Hello Michael,

The functionality has not been implemented yet and I cannot commit to any certain time-frame when it might be available. I suggest you follow the public item for this in our Ideas & Feedback portal to be notified about any progress on the matter: Add support for IF and ASK fields.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Michael
Top achievements
Rank 1
answered on 11 Jan 2016, 04:40 PM

Hi,

Since last update, "¬" character does not work anymore.  It showed up on my old template instead of being used as optional next line.  Did something change recently?  did you implement the some sort of "IF" option in Mail Merge? 

0
Michael
Top achievements
Rank 1
answered on 11 Jan 2016, 05:19 PM

I just want to add to my comment above.  I re-downloaded the sample you provided in the past and updated Telerik components.  It is not working correctly.  This is what I see on the merged document

1 High Street¬London¬Text after fields

0
Petya
Telerik team
answered on 15 Jan 2016, 12:13 PM
Hi Michael,

We already discussed this in the support ticket you submitted on the matter, but I'll add the information here as well in case anyone else encounters an issue.

As of Q1 2015 the workaround provided earlier in this thread doesn't function due to a change in the way RadRichTextBox handles the line break symbol. For the time being we're unable to propose a solution, but implementing this feature should allow us to do so: Threat Vertical Tab symbol (' ', also '\v' in .NET) as line break.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Michael
Top achievements
Rank 1
Answers by
Petya
Telerik team
Michael
Top achievements
Rank 1
Share this question
or