Expand my Community achievements bar.

Assigning a value to a global binding

Avatar

Former Community Member
I'm using a Global binding for a header field called ReportClassification. It ensures that if the user changes the value of the field, all the fields will be kept in sync.



How do I pre-assign a value to the global so that the fields wil be pre-populated? I thought about having an initialize event that does the following :



global.ReportClassification="UNCLASSIFIED";



Doesn't seem to do anything.
9 Replies

Avatar

Former Community Member
Richard,



Try doing ReportClassification.rawValue = "UNCLASSIFIED"; in javascript in the initialize event. This will set all the fields named ReportClassification fields to that value initially.



Let me know if this works or was not what you were looking for.



Catherine

Adobe Systems

Avatar

Former Community Member
Thanks for the quick response. That worked. Only thing is that I had to put the full Xpath to the element in the header page.



ReportForm.pageSet.Page1.Header.ReportClassification.rawValue="UNCLASSIFIED"



If I just put ReportClassification.rawValue the field wasn't found.

Avatar

Former Community Member
You don't have to do this with Javascript. Simply set a default value for one of your text fields (on the Object-->Value tab) and that value will automatically be copied over to your other fields.



PS - The reason you had to put the full path to the field was probably because of where you put your script. If you had put your script in the initialize event for your ReportClassification field, you could have used the following code:

this.rawValue = "UNCLASSIFIED"; (Javascript)

$.rawValue = "UNCLASSIFIED"; (FormCalc)

Avatar

Former Community Member
Thanks. Makes sense.



On a related topic, I have an Adobe Dialog where the user selects the classification and then clicks Ok. When the commit method is called for the dynamically created dialog I want the selected classification to be put in the ReportClassification field. I tried using the full path to the ReportClassification node again (like I used to initially set it) but it didn't work. Any idea why I can't set the value of this node from a dialog commit method?



I find the documentation on the Adobe dialog very sparse.

Avatar

Former Community Member
Richard



Are you still using JavaScript? All of the objects and syntax used must be in the one dialect of scriptig in the single event to work,and this is a trap I have fallen to a few times - copying a piece of sample code from somewhere and then forgetting to check the language..



You could try using JavaSript Prompt instead, I have a feeling we had that working in another project somewhere..



It could just be that the Adobe Dialog object does not deal with JavaScript syntax that well or something to that effect.



Good luck,

Sanna

Avatar

Former Community Member
Yep. I'm still using Javascript. Maybe I need to understand how the Master Page fields are referenced from Pages. Essentially I can change the value of a master field from the master page field's initialize method. When I try to change it from the page (eg. in the pages initialize method or when the OK button is pressed on the dialog and the commit method is called) it doesn't update. There is no error but it just doesn't change.



I've tried alerting the element from the commit method and I can get the element's value. I just can't set it. Is there some security issue doing on there. You can't change a master field value from a page.



eg. In the commit method or in the initialize method of the page.



app.alert("element="+ReportForm.pageSet.Page1.Header.ReportClassification);

- returns [object XFAObject]



app.alert("element.rawValue="+ReportForm.pageSet.Page1.Header.ReportClassification.rawValue);

- returns UNCLASSIFIED



ReportForm.pageSet.Page1.Header.ReportClassification.rawValue="SOMETHING ELSE";

- no change in the value

Avatar

Former Community Member
Do you have the default binding set to Global on both the Master and Body pages? With the default binding set to Global on both I was able to set the rawValue in the form's initialize method and have it show up in the fields on both master and body pages.



What I did:



- Create new form

- Add a data connection

- Drop a field from the data connection onto a body page

- Drop a field from the data connection onto a master page

- Set each to Global binding

- In the form's initialize: myfield.rawValue = 'hello';



This initializes both fields to say 'hello'.



Hope this helps..

- Steve

Avatar

Former Community Member
The field on the master page is bound globally to ensure that when the field is displayed on each Page in the form it is the same value. I don't have another field on each Page with the same name. I just use the master page field. I do have a field at the bottom of the master page with the same name though. This is because I want the classification displayed top and bottom on the page.



I thought that the Master pages elements were essentially copied into each page's element tree. Therefore I had to make it global. This may not be the case.

Avatar

Former Community Member
Turns out that the initialze method of the Master Page is called when the value is changed on the global field and this was overwriting what I was setting it to. Weird!



I moved the code in the master page field's initialize method to the docReady event in the 1st page and it works fine.