Expand my Community achievements bar.

Create unique Form ID - Help on Date Format in Concat

Avatar

Former Community Member

I am having problems formating a date value in my concat statement.  I have tried to write is different ways and still can't seem to get the string correct.

Ideally, I would like to change the date value to a Julian value for the form ID, but I would settle for just mmddyy value without the / or - in between.

Codes I have tried w/out date format string

JavaScript - Calculate

Program.FormID.rawValue=Program.State.rawValue + Program.ProgramNumber.rawValue + Program.ProgramDate.formattedValue;

Returns - MO1234Jul8,2010

-------------And--------------------

Program.FormID.rawValue=Program.State.rawValue + Program.ProgramNumber.rawValue + Program.ProgramDate.rawValue;

Returns - MO12342010-07-08

FormCalc - Calculate 

(This one has the current date as a value, but it changes the unique form ID when reopened on another day, that is why I am using ProgramDate)

Concat(Date2Num(Date(), "ddmmyyy"),Program.State.rawValue, Program.ProgramNumber.rawValue)

Returns - 0MO1234

----------- And --------------------

if

(Program.ProgramNumber.rawValue ne null) then

$.rawValue

= CONCAT(Program.State.rawValue, Program.ProgramNumber.rawValue, Program.ProgramDate.formattedValue)

else

$.rawValue = ""

endif

Returns - MO1234July8,2010  (formattedValue)

              MO12342010-07-08 (rawValue)

------------------------------------------------------------------------------

What would be the better  language to use, FormCalc or JavaScript for this example?

I am not all that skilled at coding and use forums like this to help me, so I appreciate any help.

Thanks in advance - Eve

13 Replies

Avatar

Former Community Member

To be able to use the date in the format that you want I woudl use Javascript to get a new Date(). Then you coudl get the individual month, day and year and concatinate each one individually (standard javascript date functions). Then you will have to add a test to your code to see if this is a new form or a subsequent opening of a form. If it is a subsequent opening then you woudl not need to generate the number again.

Hope that helps

Paul

Avatar

Former Community Member

Whoooshhhhh.....    A little over my head, I hate to ask, but can you dumb it down for me?

JavaScript is the way to code it - got that.  I would prefer to use an existing date field instead of the current date.  But I will use the method you think is appropriate for what I am trying to do.

Avatar

Former Community Member

Date() = Current Date

--------------------------------


FormCalc - Calculation

(I know, not JavaScript, but I  can't figure out how to do it in JavaScript - Looking it up  now)

if (Program.ProgramNumber.rawValue ne null) then

    $.rawValue = CONCAT(Program.State.rawValue, Program.ProgramNumber.rawValue, Num2Date(Date(),"YYDM"))
else
    $.rawValue = ""
endif

Returns - MO12341087

------------------------------------

With this script, I like the output but the Form ID changes when you open it or submitted a different day.

Avatar

Former Community Member

Here is my JavaScript - Calculate event (LiveCycle Designer ES 8.2)

Program.FormID.rawValue=Program.State.rawValue + Program.ProgramNumber.rawValue + Program.ProgramDate.formattedValue (or rawValue);

How would I format the date string in the concat to return just numbers and not the date?

Avatar

Former Community Member

You will have to manipulate the string that is returned to get what you want. You coudl use code like this (assume StartDate is the name of the field that holds the date:

     var userDate = StartDate.formattedValue;

     //xfa.host.messageBox("The formattedValue for Start Date is: " + userDate);

     // Parse the date values from the Date/Time field.

     // The rawValue format is YYYY-MM-DD

   

     var theYear = userDate.substring(0,4);

     var theMonth = userDate.substring(5,7);

     var theDay = userDate.substring(8);

     //You could simply use these variables or create a date object like below.

     // Create a JS date object, useful for date manipulation.

     var  dateObj = new Date(theYear,theMonth,theDay);

     var myMonth = dateObj.getMonth();

     // As a test, display the month.

     xfa.host.messageBox("The Month is: " + myMonth);

There are other javascript functions that will return the year and the day of the month for this object. Simply look up date functions in javascript and you will see them.

Hope that helps

Paul

Avatar

Former Community Member

The variable would be placed on the Date field I am using or the text field that I am concating in?

Avatar

Former Community Member

Date.prototype.yyyymmdd = function() {
  
var yyyy = this.getFullYear().toString();
  
var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
  
var dd  = this.getDate().toString();
  
return yyyy + (mm[1]?mm:"0"+mm[0]) + (dd[1]?dd:"0"+dd[0]); // padding
};

Now, after having spliced the internal Date object, you can do this:


d = new Date();
d
.yyyymmdd();

The line above returns today's date: "20100709".

Avatar

Former Community Member

Paul and c@tc.se  - Thanks

I created a hidden date field and applied c@tc.se code to that field to get to desired date output.  In my Form ID, I added that hidden date field to the Concat statement. 

Now, I need to figure out how to keep that hidden "current" date field from changing the form ID when it is opened on another day, does anyone know how to do that?

Avatar

Former Community Member

If its a new form that field should be empty so:

if (fieldname.rawValue == null){

     execute your concat code

}

paul

Avatar

Former Community Member

The form will be empty at first.  Staff will fill out a few fields, save it (w/form ID in the name) and will distribute it out.  The form ID will distinguish it from others, that is why the date can not change after they fill in the data and distribute it.

So if I replace this to the Form ID concat code, this will prevent the date from changing when the distributed form is returned?

if (fieldname.rawValue == null){

     execute your concat code

}

Avatar

Former Community Member

That broke it.  The concat isn't working now, just gives me a 0 value.  I must have done something wrong.

form1.Program.FormID::calculate - (JavaScript, client)

if

(Program.idDate.rawValue==null){

Program.FormID.rawValue

=Program.State.rawValue + Program.ProgramNumber.rawValue + Program.idDate.rawValue;

}