Expand my Community achievements bar.

auto increase number to fill field

Avatar

Level 5

Hi All.

Is it possible to create field in a form where number will incrase by 1 automaticaly each other time when form will open? I will appraciate for sample.

Thanks.

1 Reply

Avatar

Level 10

Hi,

If you are opening the same instance of the form then you could add some JavaScript code like;

var autoNumber = xfa.datasets.resolveNode("formState.autoNumber");

if (autoNumber == null)

{

    // If our 'formState' dataset does not exist then create it with a value of zero.

    var formStateXML = <formState><autoNumber>0</autoNumber></formState>;

    var formState = xfa.datasets.createNode("dataGroup", "formState"); // Note the 'formState' in this line becomes the top node not the 'formState' in the XML

    formState.loadXML(formStateXML.toXMLString());

    xfa.datasets.nodes.append(formState);

}

else

{

    // If our 'formState' dataset does exist then increment the autoNumber property.

    autoNumber.value = (parseInt(autoNumber.value,10) + 1).toString(); // Can only assign strings to a dataValue object

}

This will create a customs dataset, called formState in this script, sort of like a custom data connection.  Once this is setup then you can reference it in your field using

xfa.datasets.formState.autoNumber.value;

Here is an example, https://acrobat.com/#d=431ge6d-3J1-teEUE2EAiQ

Hope this helps

Bruce