- Mark as New
- Follow
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
I remember a client asking me something like this once but being too busy and it having low priority, I decided to shelf it.
Now that I'm not busy, I'm glad I ran into your question and took a couple hours to whip this up. Here's how the script works:
1) The form saves the current xml of the entire form in a global variable
2) It then prompts the user for the xml to import into the form. Overwriting all data in the form
3) Form saves the xml of just the subform for which the newly imported data applies to into another variable
4) Reloads the saved xml from the first variable just before the import occured
5) Then uses the second variable with the subform data and overwrites the subform
The following code also makes a few assumptions:
1) Your form is bound to a schema
2) Only subforms can be used as parameter to the mergeData function not fields
3) The subform used must itself be bound to a data node. Not just the fields it contains.
Put this in the click even of your 'Import' button:
//Save the current state of the form in a global Acrobat variable
global.formXML = sanitizeData(xfa.datasets.data.saveXML('pretty'));
//Show the import XML dialog
xfa.host.importData();//Removes the xml header
function sanitizeData(xfaData) {
xfaData = xfaData.replace(/<\?xml\sversion="1.0"\sencoding="UTF-8"\?>/,"");
return xfaData;
}
Because the form requires time to merge the data before execution is continued, the following must be put in the form:ready event:
if (typeof(global.formXML)!='undefined')
mergeData(YourSubformHere);//Enter the SOM expression of the subform you want to importfunction mergeData(oSubform){
//Save the subforms data
var subformXML = sanitizeData(xfa.datasets.data.resolveNode(oSubform.dataNode.somExpression).saveXML('pretty'));
//reload the entire forms data from the xml import in the click event
xfa.datasets.data.loadXML(global.formXML,1,1);
//global variable no longer needed
delete global.formXML;
//Load the new subform data stored in variable subformXML
xfa.datasets.data.resolveNode(oSubform.dataNode.somExpression).loadXML(subformXML,1,1);
xfa.form.remerge();
}//Removes the xml header
function sanitizeData(xfaData) {
xfaData = xfaData.replace(/<\?xml\sversion="1.0"\sencoding="UTF-8"\?>/,"");
return xfaData;
}
A lot to take in but I hope it solves your problem.
Let me know.
Kyle
Views
Replies
Total Likes