Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

In place variable substitution form1.page2.variable.rawValue

Avatar

Level 3

Hello everyone,

I am trying to do this using formcalc:


var boostDate = "boosterDate1"

form1.page2.invoiceTable.row1.boostDate.rawValue = Num2Date(Date2Num(form1.page2.page2Date.formattedValue, "MM/DD/YYYY") + (firstRowWeek * 7)
+ (firstRowYear * 365), "MM/DD/YYYY")

I want to use a variable in place of the object name but for the life of me I can't get it to work using formcalc.

Thank you for any and all help.

Justin

6 Replies

Avatar

Former Community Member

I don't use formcalc much, but I would not expect that to work. The variable you created is a String, not a Node in the heirarchy. var boostDate = form1.page2.invoiceTable.row1.boosterDate1 might work to then call .rawValue off latter.

I expect there is a reason you are using a string though. Try:

form1.page2.invoiceTable.row1.resolveNode(boostDate).rawValue = Num2Date(Date2Num(form1.page2.page2Date.formattedValue, "MM/DD/YYYY") + (firstRowWeek * 7)

If the syntax is not perfect, resolveNode is still going to come into play somewhere resolving a String to an Node.

Avatar

Level 3

Hey Steve I couldn't get it to work so instead I created an invisible field to retain the variable data and just update that field instead.  This is a very inefficient way of doing things for sure but I couldn't figure out a better solution.  I really appreciate your feedback!!!!!

Avatar

Former Community Member

Instead of hidden fields, you can use xfa.data.resolveNode({node in your data heirarchy})

That probably would seem just as messy to you if not more if you have not defined a schema. The first step for me when creating a new form is to define a schema for the data. I then define that as a data connection and bind all the form fields to the appropriate field in the data connection. You can then reference schema elements that are not bound through xfa.data. I then never have to wory about moving elements on the form changing the reference to the data. The saved file is smaller because extra sub forms created for layout purposes are not stored in the data structure.

Avatar

Level 3

Hello!!!!  I wanted to say thank you quick for all of your information thus far as every little bit helps on our educational journey. 

I have a question though.  Do you happen to have a form that I could see how you do things. I would really like to stick with best practices as I'm pretty new to programming pdf's using Formcalc and js.  I'm not completely new to js but I've only used Formcalc a few times now over the past 3 years and haven't done a whole lot with XML either.  If there is a good solid tutorial for best practices please point me in the right direction also.

I have just started to research inserting data to a mysql db using php from a pdf so if you happen to know of a good solid educational tool for this I would greatly appreciate it.

Thank you in advance for any advice or information you can give me.

Justin

Avatar

Former Community Member

Form, schema, datafile

https://docs.google.com/file/d/0B851Fdu_42hLOS1OU0QtcmVfYjA/edit?usp=sharing

https://docs.google.com/file/d/0B851Fdu_42hLTnNYZjdFeHFQM3c/edit?usp=sharing

https://docs.google.com/file/d/0B851Fdu_42hLeERHTnZPN2VQYm8/edit?usp=sharing

The 4 text fields are bound to 4 fields in the schema. I also created a list in the schema and bound a drop down list's items to that. By default, you can't bind the list items that way. You have to turn that feature on in Designer's settings. The Sample data for the list contains TextField1, TextField2 and TextField3 for list items. You can see in the calculate event of TextField4, that it's value is derived from whichever TextField you choose in the drop down. The visible/invisible stuff is because I am also posting these in response to someone else.

Avatar

Level 10

I think it might not be working because you're assigning a string to the variable, try it without the quotes so it gets the field name.