Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

## Convert function for lifecycle

Former Community Member
Hi, Before I switched over to lifecycle, I created a simple function for date entry edits. This function had 2 purposes;

A. take a full date and convert it to the DDMMMYYYY format AND

B. take a partial date and convert it to the MMMYYYY format.

I don't know if there is an easy way to do that without functions, but i have been playing around with lifecycle for a few hours now, with no results. This function did work with Acrobate PRO 8. I am not sure if the code would work with lifecycle and i am either further confused on how to call a function in lifecycle.

I'm sure this function could be done a heck of a lot easier, and with less work, but I havn't written code in about...4 years, so getting back into it is tough (and even then it was C# and ColdFusion)

~+~+~+~+~+~+~+~+~+~+~

function fixDate()

{

//----Variable assignment----

var fieldValue= event.value;

var myArray = fieldValue.split("/");

var monthName= new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");

myArray[0] = monthName[myArray[0]-1];

//----end Variable assignment

//----set year prefix to '20' if last two didgets are less then 16----

if(myArray[2].length < 3)

{

if(myArray[2] <= 15)

{

myArray[2] = "20" + myArray[2];

}

else

{

myArray[2] = "19" + myArray[2];

}

}

//-----------------------------

//----add a 0 if single didget date is given----

if (myArray[1].length == 1)

{

myArray[1] = "0" + myArray[1];

}

//----If no Day is given----

if (myArray[1] == "")

{

// app.alert(myArray[0] + "/" + myArray[2]);

event.value = (myArray[0] + "/" + myArray[2]);

}

else

{

// app.alert(myArray[1] + "/" + myArray[0] + "/" + myArray[2]);

event.value = (myArray[1] + "/" + myArray[0] + "/" + myArray[2]);

}

}
7 Replies

Former Community Member
There shodul be very little change required. The javascript is the same for both but the access to Acrobat objects will be different. I am not an Acroform specialist but the only code I see that I am not sure about is event.value. What does that return.

In XFA forms you can create a scripting object (that is where you shodul put your code). Then you can call your function by using the scripting object name.functionname()

Former Community Member
event.value is the value inside the box once changed.. i think it becomes 'name'.rawValue in XFA.

Scripting object was created, i may have been calling the function incorrectly, i was just using functionname(). i'll play around some more and see what happens. thank you

Former Community Member
The equivalent function in XFA is fieldname.event.newText

Former Community Member
cool. i'll try using that. At the same time, I think i'm calling the function incorrectly still.

I tried this.fixdate(), datebox1.fixDate(), datebox1.fixdate(this.rawvalue), and a few other combinations of those to try and get it working. To test, i just made a simple function that i know works, but it isn't getting called.

Former Community Member
In the heirarchy view ...right click on the root object (usually it is form1). Choose the "Insert Script Object" option. It will put an object called "Script Object" under the variables portion of the tree.

Highlight the script object in the hierarchy and hit F2 to rename it. Call it what you want (I will use myScriptObject). With the new script object highlighted the Script editor will show you what is in your script object. Paste your function in there (note that you cannot choose an event). Now your function is ready to use.

When you want to call it you woudl use:

myScriptObject.functionName()

Former Community Member
yea, for some reason I still can't call the function, if I copy and paste the code into the actual date/time box, it works fine, but using

fixDate.fixdate() in the box doesn't seem to want to call the function.

Former Community Member
ok... apparently, the script object CANNOT be the same name as the Function. that's where I was hitting an issue. Thank you again for the help.