Did that code post correctly?
I would expect these lines:
var name = \"NewWidget\" + this.numFields;
var field = this.addField(name, \"button\", 0, box);
var name = "NewWidget" + this.numFields;
var field = this.addField(name, "button", 0, box);
and these lines:
var sourcefield = master.getField(iconname);");
var icon = sourcefield.buttonGetIcon();"
var sourcefield = master.getField(iconname);
var icon = sourcefield.buttonGetIcon();
My apologies. Those lines are actually as you described when published in the document. I had copied the JS code from the C# project that generates the strings in the JS that gets emitted to the file. I guess I didn't clean it all up properly. In the actual document, everything works correctly in terms of syntax, just not in terms of functionality.
Does the button get created in the child document? If so, does it have the correct buttonPosition setting?
The button does exist, and the position is correct. This code is already proven to work when the icon and the button are in the same document. It just isn't working when we have an icon object from another document.
If it's any additional help, I was able to get the properties off of the exception being thrown:
property: name value: [GeneralError]
property: message value: [Operation failed.]
property: fileName value: [Console undefined:Exec]
property: lineNumber value: 
property: extMessage value: [GeneralError: Operation failed.
property: number value: 
property: stack value: [Error()@:0
I'm stumped. The error message doesn't seem to make much sense.
Edit: I was referring to the error message you posted in your initial post.
Another edit: scratch the part about it not making sense, but I don't know what could be wrong.
My next step would be to set breakpoints on each line in the function and step through the code to see if it makes a difference.
I've run the same script through the console with the same effect. After each and every line, I checked the results to make sure everything was created as expected. Every line worked just fine, all returned valid data, except for the Field.buttonSetIcon line that throws the exception.
You may need to convert the Icon to an Icon stream object and transfer that object or values between the PDFs.
I've gone and tried using Icons and IconStreams. It would seem there is only a narrow opportunity here. The way I went ahead and tried this:
- get an Icon as we've already been able to do
- use util to get an IconStream from the Icon
- use Collab to create a new StateModel, using the IconStream as one of the options
- create a new Text Annotation
- set the state model to the model created in step 3, and set the state to the entry that has the IconStream
But we can't get our IconStream to appear on the document.
After all this, we're still not getting things working as expected. Mostly because even if we could get an IconStream to work across boundaries like this, there is no method to convert an IconStream back to an Icon as we would want it to be, and the only other option using an unconverted IconStream is to use the Text Annotation with a custom StateModel, but this doesn't really work or fit our needs.
Just as a test, what happens if you copy the icon from an existing button in the child document instead and use it to set the icon of the newly created button?
Therefore, transferring the icon to the target document, and then pass it on to the field should work.
Are you saying we need to create a second static hidden button in the target document, duplicating the data stored in the source document? In other words - are you saying there is no way to do what we want to do? I take it this is what you mean, but I want to be sure.
Or is there some way to transfer the icon to the target document using JS that does not involve calling buttonGetIcon on the button in the source document?
I think he meant to copy the icon from the button in the parent document to a document icon (doc.addIcon) in the child document, and then copy this newly added document icon to the newly added button in the child document.
Getting and setting button icons within the child document works as expected, as long as the button originally existed as a resource of child document. I've not had any luck copying the icons from the child to the master either.
When we try to doc.addIcon on the other document, the call silently fails, returning null.
We tried the global variable options. I wasn't aware you could use variables other than bool, number, and string. We'll have to see if we can put this to good use now, but even so, this doesn't gain us anything in this instance. We've always had access to the icon object in the child document. When our JS is executing, we have both a "master" and "child" doc as variables. In both of these, we're able to add and get fields, get and set icons, etc. So when we're in the child document, we still have an Icon object that we got from one of the master's fields. In this case of adding it to a global and then retrieving it from the global, the variable hasn't changed any, and is thus the same variable we would have access to if we didn't put it into the global first. When passed through the global object, the same error as before is still returned.
The WindJack (awesome tool, we love it) and FormRouter tools only deal with IconStreams. All these techniques and tricks do seem to be helpful in those scenarios, but IconStreams can be created from Icons, but not the other way around, thus these other tools aren't particularly useful to us. If we could find a way to use an IconStream to make something appear within our document, then we could work with that, but I've tried and haven't been able to get any of that to work. Our best results for the appearance we desire for our annotations is to user button fields and to use Icon objects to set the appearance of them. We're open to other methods, but really, we would just want Icon to work.
Did you ever figure out how FormRouter got their icons to appear from their scripts?
They were created outside of the script and added t the script as a text field.
I am stating that you will have to somehow get the original icon into the target
If I understood your scenario, you do have a "master" document from where you take all the icons.
The (probably) easiest way to get them to the target document would be to place all the fields from which you would grab the icons onto one single page, and then attach that page to the target document. Then you grab and transfer the icons using the buttonGetIcon() / buttonSetIcon() combination. Finally, you delete the attached source page. This method would also provide you a possibility to elegantly add document-level scripts to the target document.
And, yes, I state tat the buttonGetIcon() / buttonSetIcon() combination works only within the same document.
You might experiment a bit further with file attachments, but then, you would have the equivalent of the buttonImportIcon() method.
Unfortunately, creating a global object, and using that one for the transfer does not work. One may consider this to be a bug, but officially, it will most likely be a feature…