For some reason, when I change the mergefield names, some issues arrise.
- *MERGEFORMAT becomes \m
- Quotes appear around the merge name. Unfortunately, salesforce cannot recognize mergefields with quotes around them
Example:
In a document, I can have a mergefiled called «representativename». When I toggle field codes, it looks like:
{ MERGEFIELD representativename \* MERGEFORMAT }
When I run the change routine, it becomes:
{ MERGEFIELD "USER_FULLNAME" \m }
The code we use was taken from this site a while back, so it may be outdated. I modified it slightly to fit the thread…
Dim doc As Document = New Document(inDoc)
Dim fieldStarts As NodeList = doc.SelectNodes("//FieldStart")
For Each fieldStart As FieldStart In fieldStarts
If (fieldStart.FieldType = FieldType.FieldMergeField) Then
Dim mergeF As Mergefield = New Mergefield(fieldStart)
'Code will need to check for current name here, replace if matched.
If replace(replace(CStr(mergeF.Name), "«", ""), "»", "") = "representativename" Then
mergeF.Name = "USER_FULLNAME"
End If
End If
Next fieldStart
doc.Save(inDoc)
doc = Nothing