Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Format given date from Date Picker to convert into quarter and year

Avatar

Level 1

Still getting used to Livecycle and not attempting to make a effort at learning Javascript at the same time. I'm was attempting to work on a form in ES4 that would use the following formula to convert a date that someone selects from a date picker to then convert that date to show MM/YYYY in a new field. I would appreciate it if anyone has a couple of seconds to take a look at this and tell me what I'm missing to make this work.

Corey

form1.#subform[0].DateField2::calculate - (JavaScript, client)

DateField1.rawValue

form1.#subform[0].DateField3::calculate - (JavaScript, client)

var date = new Date(DateField1.rawValue);

var month = date.getMonth()+1;

var year = date.getFullYear();

if (DateField1.rawValue == null)

  {this.rawValue="";}

else

{

if (month<=03)  month="03";

if (month<=06)  month="06";

if (month<=09)  month="09";

if (month<=12)  month="12";

this.rawValue = month+"/"+date.getFullYear();

}

2 Replies

Avatar

Level 10

Hi,

to make this work the field that shows the quarters cannot be a date field.

You should use a text field instead.


form11.#subform[0].Textfield1::calculate - (FormCalc, client)



if (not DateField1.isNull) then


  var vDate = Date2Num(DateField1.formattedValue, "MM/DD/YYYY")


  var vMonth = Num2Date(vDate, "M")


  var vYear = Num2Date(vDate, "YYYY")


  var vQuarter



  if (Within(vMonth, 1, 3) eq 1) then


  vQuarter = "03"


  elseif (Within(vMonth, 4, 6) eq 1) then


  vQuarter = "06"


  elseif (Within(vMonth, 7, 9) eq 1) then


  vQuarter = "09"


  else


  vQuarter = "12"


  endif


  $ = Concat(vQuarter, "/", vYear)


else


  $ = null


endif


Avatar

Level 1

Any way to convert this in Javascript?