Expand my Community achievements bar.

SOLVED

Change format of a date field to use as part of a file name.

Avatar

Level 1

Good afternoon!

I am using Livecycle ES3 and Adobe Professional XI

I have a livecycle form for employee evaluations.

I am saving a file based on field names.  My problem is when I use a date field as part of my file name.  I have the scripts working for the trusted function and for the button field on the form.  They are listed below.

Folder level script--

mySaveAs = app.trustPropagatorFunction(function(doc, path)
{
     app.beginPriv();
         doc.saveAs(path);
     app.endPriv();
});

myTrustedSpecialTaskFunc = app.trustedFunction(function(doc, file_path)
{
     // Privileged and/or non-privileged code above
     app.beginPriv();
          mySaveAs(doc, file_path);
     app.endPriv();
});

Button script

 

myTrustedSpecialTaskFunc(

this, "/c/myfiles/" + ReviewPeriodTo.rawValue + "-" + Div.rawValue + "-" + EVALTTYPE.rawValue + "-" + LASTNAME.rawValue + "-" + FIRSTNAME.rawValue +

".pdf");

My problem is the ReviewPeriodTo.rawValue.  When I enter the data into the form and don't enter a value for ReviewPeriodTo field, the file is saved with the values from the other fields, and a null is inserted where the date field would go.

When I type in a value such as 2014-03-15 in the ReviewPeriodTo field along with values in the other fields, it works.

When I try to put a value in such as 3/15/2014 in the ReviewPeriodTo field, I receive the following error.

RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.

Doc.saveAs:16:XFA:form1[0]:Page1[0]:#subform[0]:Button3[0]:mouseUp

===> The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.

My problem is, this is part of a much larger process where I am importing the information from a make table query from MS Access that is exported to Excel.  If I could just format the field data automatically to the yyyy-mm-dd forma from that t, that would work, but I do not know how to do coding in MS Access. 

How can I format the data that is input into the form to be the yyyy-mm-dd format?

I have tried changing the display and data format through livecycle patterns for the field, but that is not working.

Any assistance would be greatly appreciated!

Thank you

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi

This sounds like you need to specify all the formats that the users can enter the date in the edit patterns.  If it matches one of the formats then the rawValue will automatically be formatted in the yyyy-mm-dd format.

So this means that if the formattedValue equals the rawValue then the date didn't match one of the edit patterns and you will need to show an error message.

Regards

Bruce

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi

This sounds like you need to specify all the formats that the users can enter the date in the edit patterns.  If it matches one of the formats then the rawValue will automatically be formatted in the yyyy-mm-dd format.

So this means that if the formattedValue equals the rawValue then the date didn't match one of the edit patterns and you will need to show an error message.

Regards

Bruce

Avatar

Level 1

Bruce

Thank you very much for responding.

I tried your suggestion, and in the preview of Designer, this works perfectly.

I have as my pattern for my edit tab as

date{MM/DD/YYYY}|date{MM/DD/YY}|date{M/D/YY}|date{M/D/YYYY}|date{YYYY-MM-DD}

pattern for the data tab is left blank

pattern for the display tab is

date{YYYY-MM-DD}

However, when I go back into Adobe and merge my data--the data comes in as it is from the merge file--which is M/D/YYYY.  I get the same error when I try to save the file as above.

If I change the pattern for the display tab to

date{M/D/YYYY}|date{YYYY-MM-DD}

and I merge the data into the form, I receive this error.

GeneralError: Operation failed.

XFAObject.next:122:App SimpleVarData:Exec

next operation failed.  [Microsoft][ODBC Excel Driver] Operation must use an updateable query.

The data is coming from an access database from a make-table query that is exported to Excel.  I don't know how to make the data from the Make Table Query change to the YYYY-MM-DD format unless I changed it manually every time the table is created.

Is there any way that I can just format the date in the button script so that it is read as YYYY-MM-DD regardless of what is in the field on the form?

Thank you for your help.

Avatar

Level 1

Bruce

I was finally able to get everything to work.  I had to go back to the excel spreadsheet and make a macro to change the format of the date field. 

Thank you so much for your assistance!