InfoPath Q&A: How do I avoid getting NaN when using the max() function?

Learn how to avoid getting the NaN error in InfoPath when using the max() function and submitting an InfoPath form to a SharePoint form library.

ADVERTISEMENTS

Brad wrote:

Hello,

I have implemented your autonumbering for infopath form solution. Works great except the first document they submit returns a NaN from the ID. Anyway around this?

Thanks,
Brad

Hi Brad,

Thanks for alerting me to this ‘bug’. I’ve updated the article to include this caveat. The max() function is failing because there aren’t any IDs to evaluate. The way to solve this issue is by using a conditional statement, so that the max() function is only used when there are IDs to evaluate.

To implement this solution, the form template would have to be constructed differently. This is a topic for another article, I’m afraid. So when I have time again I’ll write another one. Since it might take a few months before I get around to writing articles again, you can have a go at constructing the solution yourself. You would have to do the following:

  1. Change the RetrieveIDs data connection to use the autonumber field instead of max(@ID) + 1.
  2. Add a Button to the form with the following 4 rules:
  3. - Query the RetrieveIDs data connection
    - Set the autonumber field equal to 1 when count(@ID) = 0
    - Set the autonumber field equal to max(@ID) + 1 when count(@ID) > 0
    - Submit the form to the form library

  4. Disable the submitting of the form via the Submit button on the toolbar (the Button you added will submit the form instead)

Hope this helps. If you have any questions, let me know. While I’m extremely short on time these days, I will still be able to give you short and quick pointers to get you ahead should you get stuck.

 


Related Posts

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.