Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

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