I have a method in a fragmentScript script object that creates a javascript object formatted like below:
customerObject
name [string]
address [string]
city [string]
state [string]
list of accounts [array]
When the script is done executing, the subform containing the script gets hidden, and needs to pass the object to another subform which becomes visible.
Can I pass this object via a form variable (located under File-Form Properties, Variables tab)? That is, can a form variable contain a complex javascript object?
Thanks,
Elaine
Solved! Go to Solution.
Views
Replies
Total Likes
Hi Elaine,
The variable tempRetCust seems to be assigned twice, the first one assigns it some XFA object (with a value property) the second one assigned it to a string (without a value property). So I think eval(tempRetCust) will work, eval(tempRetCust.value) would be the same as eval(undefined).
Bruce
Views
Replies
Total Likes
Yes. For example, the attached form contains text fields and list box of accounts.
var customer = new Object();
customer.name = form1.page1.subform1.name.rawValue;
customer.address = form1.page1.subform1.address.rawValue;
customer.cty = form1.page1.subform1.city.rawValue;
customer.state = form1.page1.subform1.state.rawValue;
customer.accounts = new Array();
var accountCnt = form1.page1.subform1.accounts.length;
for (var i=0; i < accountCnt; i++) {
customer.accounts[i] = form1.page1.subform1.accounts.getDisplayItem(i);
}
xfa.host.messageBox("The customer name is " + customer.name);
xfa.host.messageBox("The first account is " + customer.accounts[0]);
Hi Elaine,
I've tried something like this before but a form variable can only hold a string value. However you could acheive what I think you want using the toSource() method and eval function.
var co1 = { name : "customer name",
address : "customer address",
city : "customer city",
state : "customer state",
accounts : [1,2,3]
};
CustomerObject.value = co1.toSource();
var co2 = eval(CustomerObject.value)
console.println(co2.name);
console.println(co2.address);
console.println(co2.city);
console.println(co2.state);
console.println(co2.accounts);
Though have you tried storing the object in a script object at a higher level in the form structure available to subforms.
Bruce
Thanks, Steve, but I think I am referring to the form variable that you select using File-Form Properties - Variables tab. I hope I am not misunderstanding your reply. Thanks for the information!
Views
Replies
Total Likes
I will try your recommendation! Thanks!
Views
Replies
Total Likes
Hey Bruce, I'm having a problem with the eval funtion returning a null, can you help me?
Here's my code snippet:
var tempRetCust = objFragment.resolveNode("returnCustomerObj"); //this is goodvar objCustomer = myCustomerObject;
tempRetCust
= objCustomer.toSource();
app.alert("tempRetCust "
+ tempRetCust); // the toSource method works great and the alert here returns proper data
var retCust = eval(tempRetCust.value);
if
(retCust==null ) app.alert ("return cust is null"); // the eval doesn't seem to work and the retCust variable is null.
Thanks!
Elaine
Views
Replies
Total Likes
Hi Elaine,
The variable tempRetCust seems to be assigned twice, the first one assigns it some XFA object (with a value property) the second one assigned it to a string (without a value property). So I think eval(tempRetCust) will work, eval(tempRetCust.value) would be the same as eval(undefined).
Bruce
Views
Replies
Total Likes
Thanks Bruce! I got it working! Thanks again! --elaine
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies