SET not working / Better alternative?

Hi, we are working with the trial of Aspose and are in the final stages of development of our product with intent to purchase Aspose.

I prefer to be able to reference a bookmark to get to values that have already been determined by complex IF statements previously. I came to realize in short order that if a bookmark is nested within the true part of an IF, it is not accessible to the document unless the IF condition is true. This makes sense, so I can’t complain too much.

I intended to use a SET as a work-around, whereby I would place it at the top of the document before any IF’s, etc. It doesn’t work. I am versed with creating fields using Ctrl/F9, so that is not an issue.

Here’s what I have:

{Set ChildOrChildren “{if {mergefield childcount} >1 “ren”}”}
The father of the child{REF ChildOrChildren} <----- this throws an Error! Unknown opcode for conditional.

The father of the child{ChildOrChildren} <----- this does not produce the “ren” and is only leaving “child,” even though childcount>1.

The output actually shows the following as regards the SET:

{Set ChildOrChildren “ren”}

Alt/F9 makes it disappear.

Since I can see that it is actually setting the value to “ren,” the problem lies in trying to refer to it.

Incidentally, the IF’s and Mergefields do not toggle with Alt/F9 and remain invisible to the end user of the output file. This is not the case with a SET, since it obviously is appearing.

I was really hoping for a way to solve my problem AND have output that reveals none of the inner-workings to the end user.

I could cut and paste the evaluations everywhere they are needed, but this is not only tedious, but it diminishes legibility of the templates we are building.

Thanks in advance for any input/recommendations.

Incidentally, Aspose throws an error if the Word template contains a comment whose bounds are within the quoted region of a true or false clause in an IF.

Ex. {if{mergefield X} = ABC “This is true, and the underlined part is really the bounds for a Word comment”}

If you try this, but instead of underlining the above text, you highlight it and attach a comment to it, it will crash when being processed in Aspose.

Please disregard the first post. I am finding the trouble also exists in Word. Sorry I did not know this first.

Second post may still be valid issue.

Here is what I learned. If anyone has experience on the issue below, input would be very much appreciated.

I think the Word 2013 changed how it handles bookmarks / SETS and REFS,
and that it is buggy and has also changed a DLL of something that my
Word 2007 uses, affecting it as well.

{SET FirstName “John”}

My name is {REF FirstName} <— output should be “My name is John”

A few things to note:

  1. Before, I used to be able to use CTRL/F9 to insert field brackets,
    and then, I could just type the text above in them. Now, this does not
    work at all, and you have to use the menu (Insert->Quickparts) to do
    it.
  2. Even using the menu, the process will work, up until you change the
    value. For example, if I enter the two lines above, it works. Then,
    if I go into the field and change “John” to “Jon,” it does not work.
    The output still shows “My name is John.”
    Yes, I pressed Alt/F9 to toggle the view.
  3. I find no way to do a {SET FirstName “{IF {something} “this” that”}"}.
  4. The SET problem also occurs with ordinary bookmarks. You can type
    “Jeff,” highlight it, bookmark it and name the bookmark FirstName.
    Like SET, it will work, but if you change the content inside the
    bookmark, the subsequent REF to it does not reflect
    the change.

Has anyone experienced this issue? All this used to work fine for me.

Hi Jeff,

Thank you for your interest in Aspose.Words.

*Jeff:
Incidentally, Aspose throws an error if the Word template contains a comment whose bounds are within the quoted region of a true or false clause in an IF.

Ex. {if{mergefield X} = ABC “This is true, and the underlined part is really the bounds for a Word comment”}

If you try this, but instead of underlining the above text, you highlight it and attach a comment to it, it will crash when being processed in Aspose.*

Could you please attach your input Word document, you’re getting this exception with, here for testing? I will investigate the issue on my side and provide you more information.

Regarding your other problems, may be you can resolve them by manually ‘Updating Field’ in MS Word or by using the Document.UpdateFields method in Aspose.Words.

Best Regards,

Thanks for your reply. I just learned a short while ago that Word is very finicky about manual field entry and that a lot of mistakes are avoidable by inserting fields via their QuickParts and Cross-Reference menu items. I am doing it that way and making good progress.

There no longer is any problem on my end.

Thanks again!

Hi Jeff,

Thanks for your inquiry. It is perfect that you can manage fixing problems on your side. Please let us know any time you have any further queries.

Best Regards,