Expand my Community achievements bar.

SOLVED

Why wont this simple while loop work?

Avatar

Former Community Member

The main idea is to create a search funcionality on a form. I want to move to the next record until I find what Im looking for. Heres the code:

// These variables get the numeric values of both the NumericField5 and NumericField8. NumericField5`s rawValue will be less than the NumericField8`s.

var strt = NumericField5.rawValue;

var end = NumericField8.rawValue;

// While strt variable rawValue is smaller than the end variable rawValue, move to the next record in the DataConnection.

while (strt < end)

{

xfa.sourceSet.DataConnection.next();

strt = NumericField5.rawValue;

}

When this is working, ill create another while loop to search when the variables are going from end to start.
Dont know why, acrobat freezes everytime. PLEASE HELP!!!
1 Accepted Solution

Avatar

Correct answer by
Former Community Member

You can store the content of the field before entering the loop then use a for loop to wait until it has changed. Then you would update the stored content with the new value so that the next time through you are waiting on the right thing.

Paul

View solution in original post

16 Replies

Avatar

Level 7

"end" may be a reserved word. Try using something like numEnd, for example, as your variable name.

Avatar

Former Community Member

Yea, sorry, i had other words there, put those just to simplify reading. wont still work.

Avatar

Level 7

Is the form trusted? The data connection may not work unless you've added the form as a trusted form.

Avatar

Former Community Member

Remove the while loop and add a button to get the next record. Cycle through the records to make sure your condition is being met. Ciuld be that you are in an infinite loop.

Paul

Avatar

Former Community Member

pguerett , i need that while loop to go right to the record Im looking for. If I remove the while loop , xfa.sourceset.dataconnection.next(); works just right, but I have to click one by one.

This is trusted, since it works when I click on a button with xfa.sourceset.dataconnection.next();

Avatar

Former Community Member

The first (start) variable got the charcodeAt on the first 3 characters of the dataconnection, converted to strings, added , then converted to numbers.

The second (end) variable got the charcodeAt on the first 3 characters from an xfa.host.response dialog box, converted to strings, added , then converted to numbers.

Avatar

Former Community Member

Understand what you are saying and I agree ....I am simply trying to validate that the condition that you set up in your

while loop will be met. By having you press the button for the next iteration in the while loop hopefully we can see what is happening ....my guess is still that you are in an infinite loop.

paul

Avatar

Former Community Member

Hey Paul, forgot to tell you that the code is implemented on a button.

I added two more textfields that got the value from both variables. Removed the while loop, and the textfields show how start value goes up to end value until they match as I click and go to the next record.

Thats the weird part, they do get to have the same value after some iterations but still will freeze.

Avatar

Former Community Member

They will still freeze when you remove the while loop or only when the while loop is implemented?

Paul

Avatar

Former Community Member

It works well when I remove the while loop...

Avatar

Former Community Member

So I think it is a timing issue. When you retrieve the record from the DB you may be moving onto the next statement in your code beofre the record is retrieved and the fields are updated. We need some way of knwoing that the record is ready. Can you add a test tho the loop to validate that data has changed on a field before doing the test?

This is just a theory but it would explain why Acrobat is being unresponsive ....

paul

Avatar

Former Community Member

Paul:

Can you add a test tho the loop to validate that data has changed on a field before doing the test?

What do you actually mean here? I need to check the timing but didnt get the complete picture. Thank you.

Avatar

Former Community Member

If a field changes each time you access a new record then you should be able to get the new record, then test the value of the field to see if it has changed, if it has then do your while loop test. This ensures that the new record has been retrieved and is ready to go.

Paul

Avatar

Former Community Member

Ah, got it. Im only able to check if a field has changed on the change event and this script is only on the click event... if only i had some method to verify the change on the same click event i would try that on an if sentence right away.

Avatar

Correct answer by
Former Community Member

You can store the content of the field before entering the loop then use a for loop to wait until it has changed. Then you would update the stored content with the new value so that the next time through you are waiting on the right thing.

Paul

Avatar

Former Community Member

Paul, Just like you said. Timing... THANK YOU!!!

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----