Expand my Community achievements bar.

Auto number each form when distributing by email

Avatar

Level 2

I need to assign a number to each form during or before emailing, anyway to do that with scripting? Thanks for all the help, I am getting so close to having everything I need for this form.

Thanks

Mike

2 Replies

Avatar

Former Community Member

Hi Mike,

I have used the following technique to auto-number a form:

1) Create a hidden field and use a FormCalc function to get the date-time when the form is opened

// form1.purchaseOrder.header.DateTimeField1::initialize - (FormCalc, client)

// The hidden field DateTimeField1 is used as the source for the P.O. number.

// The function, below, returns a string in the format 20081107055344 where 20081107 is YYYYMMDD and 055344 is HHMMSS.

$.rawValue = Concat(Num2Date(Date(), "YYYYMMDD"), Num2Time(Time(), "HHMMSS"));

2) On the target id field extract the month, day, and time (down to the millisecond)

// form1.purchaseOrder.header.poNum::calculate - (JavaScript, client)

// DateTimeField1 is used to generate a unique P.O. number (see the initialize event on DateTimeField1).

// DateTimeField1 produces a value in the format 20081107055344, for example. In this example the substring

// removes the year 2008 to produce the P.O. number 1107055344.

var str = form1.purchaseOrder.header.DateTimeField1.rawValue;

this.rawValue = str.substring(4,18);

There are many techniques including the creation of a random number using the JavaScript math.random() method.

See https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math/random

Steve

Avatar

Level 2

Thanks Steve, I'll give it a shot. Will this lock the number in so it will not change if the customer opens it again? So they can have a reference number to give me to find their request? It seems like it changes everytime it is open.

Thanks

Mike

Message was edited by: AEMIKEA