IT Process Automation

 View Only
  • 1.  Facing issue in manipulating date string.

    Posted May 03, 2018 06:24 AM

    Hello All,

    In one of our PAM process, developed by our ex-developer, I am trying the following code to get back the date string in form of m/dd/yyyy (for eg. 5/10/2018).

    Here, our objective is to get a date string (for e.g. 5/10/2018) from database table, increment the date with 7 days (such as, 5/17/2018) and insert this incremented date string into database table.

    Here, date field in table is of VARCHAR2 type.

     

    /********** code snippet*************/

     

    1.

    2. function addScheduleNextStartDate(existingStrtDt){

    3.       var datestr = existingStrtDt;
    4.       var curr_date = new Date(datestr);

    5.       
    6.      
    7.      

    8.       var mm = curr_date.getMonth(curr_date.setMonth(curr_date.getMonth()+1));
    9.       var dd = curr_date.getDate(curr_date.setDate(curr_date.getDate()+7));
    10.     var y = curr_date.getFullYear(curr_date.setFullYear(curr_date.getFullYear()));

    11.       var newDatetoSet = mm+"/"+dd+"/"+y;

    12. return newDatetoSet;

    }

     

           //here 'startdt' is a date string (for eg. 5/10/2018) and 'scheduleNextStartDate' is a dataset of string type 

    13. scheduleNextStartDate = addScheduleNextStartDate(Process.RequestList[j].startdt);

         

     

    /*** Code end****/

     

    I am getting following output here in 'scheduleNextStartDate' as 00/17/2018

    Here, I am getting month as 00

     

    For trial, I swap the code (i.e. line number 8 and 9) as below, 

       var mm = curr_date.getDate(curr_date.setDate(curr_date.getDate()+7));   //here I tried to call getDate() 
       var dd = curr_date.getMonth(curr_date.setMonth(curr_date.getMonth()+1));    //here I tried to call getMonth()
       var y = curr_date.getFullYear();

    In this case for date string '5/10/2018' I am getting output as '00/5/2018' for var newDatetoSet = mm+"/"+dd+"/"+y;

     

    As we can see,

    In 1st case, I was getting month as 00.

    and in 2nd case, I am getting date as 00

     

    I tried to investigate this in every possible way, but I am failing to identify where/what am I doing wrong?

    I also tried generating a date with the help of Date() and then using formatDate(date,'M/dd/yyyy') in order to get the date string. But in every case the output scenario is the same.

     

    For testing purpose, I created a separate test process in which I am passing a date string, say 5/13/2018 from one JS operator to another JS operator. In second JS operator I tried the same code and here I am getting an expected output, i.e. 5/20/2018.

     

    Any suggestion or solution will be of great help.

     

    Thanks and Regards!

    Aniket Khandar



  • 2.  Re: Facing issue in manipulating date string.

    Posted May 03, 2018 01:50 PM

    Hi,

    Until pam update its javascript engine, wich we believe will happen in the next sp, you shouldn't use any javascript date function. Instead, use PAM's own functions, 

    This one will get current date now(). if you don't need the time, use today() (now Function - CA Process Automation - 4.3 - CA Technologies Documentation)

    This one will format the date for what you need. formatDate() - formatDate Function - CA Process Automation - 4.3 - CA Technologies Documentation 

     

    People usually have a hard time calculating Dates using pam, but when you use the correct functions it's as you'd expect it should be.



  • 3.  Re: Facing issue in manipulating date string.

    Posted May 04, 2018 02:02 AM

    Hello Marcel,

    Thank you for the suggestions, but using now() or today() will not serve the purpose.
    I will explain the scenario again.

    I am picking date string (date is stored as string) stored in database table. Then, I am generating a date from this date string by using 'var curr_date = new Date(datestr)'.

    Once the date is created, I am trying to increment this date by 7 and then this date should return as a string and should get assigned to 'scheduleNextStartDate' dataset (since, this dataset is declared as string).

    But every time I am getting 00 in my 'mm' variable, no matter which function I am calling.

    var mm = curr_date.getMonth(curr_date.setMonth(curr_date.getMonth()+1));

    and 

    var mm = curr_date.getDate(curr_date.setDate(curr_date.getDate()+7));

     In both the cases, the value 00 is getting stored in 'mm' variable.

     

     



  • 4.  Re: Facing issue in manipulating date string.
    Best Answer

    Posted May 04, 2018 10:03 AM

    Try this:

    var YYYY = "";
    var MM = "";
    var DD = "";
    var futureDate = "";
    var d = new Date("4/30/2018");
    var dayOfMonth = d.getDate();
    d.setDate(dayOfMonth + 7);
    YYYY = d.getFullYear().toString();
    MM = (d.getMonth() + 1).toString();
    DD = d.getDate().toString();
    futureDate = MM + "/" + DD + "/" + YYYY;