Answers / JavaScript
assumming my connection and everything else is correct. I would like to do this: var cRecordii = xfa.record.nodes.item(nIndex); var cCurrentBalance = 0; for (var nColIndex = 0; nColIndex < cRecordii.nodes.length; nColIndex++){ switch(cRecordii.nodes.item(nColIndex).name) { case "CurrentBalance": cCurrentBalance = cCurrentBalance.value + cRecordii.nodes.item(nColIndex).value; break; default: break; } }However it is not working.
david romero 439 days ago
Wouldn't be great if it worked that way. But it doesn't, a script can read from the source model, but only a bound field can write into it. I usually setup a group of invisible fields for exactly this purpose. You'll find videos and samples covering this topic ad nauseum at this membership site:http://www.pdfscripting.com/public/department36.cfm Thom ParkerThe source for PDF Scripting Info pdfscripting.comThe Acrobat JavaScript Reference, Use it Early and OftenThe most important JavaScript Development tool in AcrobatThe Console Window (Video tutorial)The Console Window(article)Having trouble, Why Doesn't my Script Work
I setup the invisible fields what would I need to do next? oLoan.resolveNode("aggCalc2").rawValue = oLoan.resolveNode("aggCalc").rawValue; oLoan.resolveNode("aggCalc").rawValue = cCurrentBalance.value; oLoan.resolveNode("aggTotal").rawValue = oLoan.resolveNode("aggCalc2").rawValue + oLoan.resolveNode("aggCalc").rawValue; Do I need a math function? I think i am assigning them to the hidden fields correctly but cannot get the last line to work.
david romero Commented 438 days ago | Report
The hidden fields need to be bound to the data connection. Then when you update the DB it updates it with the field values.
Thom Parker Commented 438 days ago | Report
Oh, I thing that you are not performing the DB operations. Look in the XFA object reference for the sourceSet model functions. Or join pdfscripting.com and watch the videos that explain this in detail.
will this work with dynamic forms i thought for a form to be dynamic you should have any fields bound to the data connection? I'm not sure I understand entirely what you are saying. I don't need to update the DB I just need to get an aggragated total or a sum of all the records from my data connection.
I appreciate your suggestions but join pdfscripting.com isn't an answer its more or a sales pitch...
Says the guy asking for free help! DB stuff isn't easy, we provide free advice for people trying to learn, not free consulting. And joining pdfscripting.com is the answer.
So does that mean with pdfscripting.com you will do the form for me? b/c you know that would be consulting... however I concede forgive me for the confusion of this forum offering answers... to my questions ... and not suggestions to my questions. so while you are technically offering an answer to my question, I am looking for the appropriate answer, if it is free or not is really terms of the service being offered which I thought were the terms to this service..... but I am not going to complain since it is free just plaining stating I need a different answer than pdfscripting.com
I can guarantee you that pdfscripting.com will answer all of your questions about LC DB programming.
Thom Parker Commented 437 days ago | Report
Ok, lets start over. You never explained what it was you were trying to do. I'm sorry I didn't ask you to explain more up front. I thought that you were trying to write back to the DB. In order to add the records you have to position the record pointer. This is standard for any DB programming on any platform. So #1 you have to learn about the Source set model and it's functionality.
No worries, I myself can be unclear and wasn't clear on my task. I have setup the data connection and setup my record pointer here: if (cCIFnumber =="") { app.alert("There is not a Valid CIF Number - try again!") } var sDataConnection = "LNMAST"; var nIndex= 0; while(xfa.sourceSet.nodes.item(nIndex).name != sDataConnection){ nIndex++; } var oDBii = xfa.sourceSet.nodes.item(nIndex).clone(1); //app.alert(oDBii.saveXML("pretty")); oDBii.nodes.item(1).query.setAttribute("text", "commandType"); oDBii.nodes.item(1).query.select.nodes.item(0).value = "Select * from LNMAST where CIFNumber = '" + cCIFnumber.value + "'"; //app.alert(oDBii.nodes.item(1).saveXML("pretty")); var sOpen = ""; try { oDBii.open(); oDBii.first(); } catch(e) { sOpen = "failed"; } if (sOpen == "failed") { xfa.host.messageBox("No items found. Please try again"); } else { nIndex = 0; while(xfa.record.nodes.item(nIndex).name != sDataConnection){ nIndex++; } var cRecordii = xfa.record.nodes.item(nIndex); var oLoan = xfa.resolveNode("oLoan"); var hForm = xfa.resolveNode("hTitle"); oLoan.resolveNode("aggCalc").rawValue = 0; for (var nColIndex = 0; nColIndex < cRecordii.nodes.length; nColIndex++){ switch(cRecordii.nodes.item(nColIndex).name) { case "CurrentBalance": var cCurrentBalance = null; cCurrentBalance = cRecordii.nodes.item(nColIndex); oLoan.resolveNode("aggCalc2").rawValue = oLoan.resolveNode("aggCalc").rawValue; oLoan.resolveNode("aggCalc").rawValue = cCurrentBalance.value; oLoan.resolveNode("aggTotal").rawValue = oLoan.resolveNode("aggCalc2").rawValue + oLoan.resolveNode("aggCalc").rawValue; xfa.host.messageBox("N: " + oLoan.resolveNode("aggCalc2").rawValue + " | " + oLoan.resolveNode("aggCalc").rawValue + " | " + oLoan.resolveNode("aggTotal").rawValu ); break; default: break; } } } oDBii.close(); } I know the Data Connection is working correctly and I know how to setup a point to step threw my records what I am having issue with is actually creating a variable or field that will sum up the records as I step through each record. I intially tried doing this by creating a case statement that caught the column header here: case "CurrentBalance": cCurrentBalance = cCurrentBalance.value + cRecordii.nodes.item(nColIndex).value; break; I hoped it would be as simple as added the value of the node (cRecordii.nodes.item(nColIndex).value) to the variable. This was not working than i tried in my lastest piece assigning the values to different fields and than totaling the fields but the line (oLoan.resolveNode("aggTotal").rawValue = oLoan.resolveNode("aggCalc2").rawValue + oLoan.resolveNode("aggCalc").rawValue;) doesn't seem to work either.
I'm not seeing the next() function used anywhere. You have to call next to go to the next record. It is as simple as you think it should be. Much, much simpler than the code you've listed. Your DB needs to be setup so that it reports an EOF. Then you write your loop to goto the next record until isEOF() is true. each time through the loop just sum the value acquired from the record model. do the sum in a variable. Wait til the loop is finished, and then apply the sum to the form field. BTW: this should all be done from a button script.
Thank you I apreciate your help!
david romero Commented 437 days ago | Report
Download Acrobat XI trial
Get the trial now
Measuring Tool in Acrobat XI
Asked by MICHAEL CHANG · no replies
Why are all my scanned documents showing up at 198%
Asked by Karen Newell · 1 answer
Suddenly I can't print a PDF I get a message "no pages selected"
Asked by Terry Rennhack · no replies
I want to create a PDF that allows users to build their own package
Asked by Kenneth Soong · no replies
mfc-5440cn
Asked by Ralf Rosenke · 1 answer
Are PDF files protected. I had an invoice designed but I can't make changes to the design,...
Asked by paul mcguire · 1 answer
Edit my profile
Get a Widget
Rewards
Last 30 Days