CA Service Management

 View Only
Expand all | Collapse all

ITPAM and CA Service Catalog - Epoch Time Format for date

  • 1.  ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Aug 10, 2016 06:17 PM

    Hi all,

     

    I am using the OOTB date component when designing a form in Catalog as per below

     

     

    Using ITPAM, the following results are returned

     

     

    The format is given as DD/MM/YYY HH:MM:SS and not Epoch.

    With Epoch format it will make coding the webservices methods into ServiceDesk much simpler.

     

    With a random date I can continue coding in ITPAM, so for now I have hard coded in my post execution code

    var temp_hold = 1470914220

    Process.NeedByDate = temp_hold;

     

    So my question is....

    Is there any option in Catalog to make the format epoch? If not, is there a one liner piece of Java code I can use in ITPAM that will help to get this date in Epoch format?



  • 2.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Broadcom Employee
    Posted Aug 11, 2016 03:37 AM

    Hi James.

     

    As for the CA Service Catalog Form Date component, the format is as explained in the following wiki page:
    https://docops.ca.com/ca-service-management/14-1/en/using/service-catalog-management/manage-forms/elements-of-a-form

    Given this, the following m,ight help you further on getting it translated into an epoch date format.

     

    1. JavaScript dates are internally stored as milliseconds since epoch.
    You just need to convert it to a number, e.g. with the unary + operator, to get them.
    Or you can use the .getTime method.
    You likely will use a regex to extract the values from your string and pass them into Date.UTC:
    var parts = datestring.match(/(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})/);
    return Date.UTC(+parts[3], parts[2]-1, +parts[1], +parts[4], +parts[5]);
    This will yield 1354604400000 ms for your example date.

     

    2. You can use the momentjs library to do this rather easily.
    var epoch = moment(str).unix();
    http://momentjs.com/

     

    Please let me know whether this helps you further?

    Thanks in advance and kind regards, Louis.



  • 3.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Aug 12, 2016 04:01 AM

    Thanks for this Louis.

    This has shown me some useful Java principles.

    Using startDate_fdm$$ as per Jason Wolfe, I simply divide this by 1000 to get the correct epoch format I need.



  • 4.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date
    Best Answer

    Posted Aug 11, 2016 01:22 PM

    From soapUI it looks like getFormRateItemValues returns both the formatted date and epoch time:

     

     <form xsi:type="ns2:FormElement">
       <ID xsi:type="soapenc:string">startDate</ID>
       <label xsi:type="soapenc:string">Start Date</label>
       <labelValue xsi:type="soapenc:string" xsi:nil="true"/>
       <type xsi:type="xsd:int">14</type>
       <value xsi:type="soapenc:string">08/12/2016 16:00:00</value>
     </form>
     <form xsi:type="ns2:FormElement">
       <ID xsi:type="soapenc:string">startDate_fdms$$</ID>
       <label xsi:type="soapenc:string">startDate_fdms$$</label>
       <labelValue xsi:type="soapenc:string" xsi:nil="true"/>
       <type xsi:type="xsd:int">0</type>
       <value xsi:type="soapenc:string">1471017600000</value>
     </form>
    
    


  • 5.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Aug 30, 2016 01:19 PM

    Hi Jason, 

    Thanks again for your help on this.

     

    With regards to your Soap method suggestion, what is the URL where I can have a look at this. 

    eg: getFormRateItemValues

     

    I only know the ServiceDesk one.....servername:8080/axis/services/USD_R11_WebService?wsdl

     

    Also, would it then be possible to get the actual time user submitted form?



  • 6.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Aug 30, 2016 02:38 PM

    You can find details from Web Services API doc from the UI under Administration > Tools > Links > Web Services API > Request Web Service

     

    Catalog exposes a wsdl URL per Web Service (i.e. Request Web Service, User Web, etc) using the following syntax:

     

    http://hostname:port/usm/services/RequestService?wsdl

     

    Note the uppercase 'R' and 'S' in 'RequestService' is necessary.

     

    Also, the form is part of the service/service option which is part of the submitted request, so if you are looking to grab the time the request was submitted, one way would be to call getRequestItems which returns 'subscribedDate'. 



  • 7.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Aug 31, 2016 08:38 AM

    Thanks again Jason, 

    So I am able now to get the submitted time. But the format is different from the selected date in the form. 

     

    If I want to get the day of the week I can use Java

    var DateSubmitted= Process.GetFormValues_2_1.ScheduledStartTime
    var n = DateSubmitted.getDay();

    This works and will return a value of 3 ( assuming today is Wednesday)

     

    However, the scheduled date (the date that will be chosen by the user) looks like this

    var DateChosen = Process.GetFormValues_2_1.arrayFormResults[6].strValue;

    var n = DateChosen.getDay();

    This fails....and I believe it is because the format of Aug 31, 2016 1:24:33PM is vastly different from 09/09/2016 22:00:00. 

     

    Have you got any suggestions on how I could get the day of the week from date_1 or from date_1_fdmss$$ ?

     

     

     

     

     



  • 8.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Aug 31, 2016 05:00 PM

    I used the following in a Catalog form to return the day of week based on epoch time:

    var etime=ca_fdGetDateFieldValueInMillis(ca_fd.formId,'date_1')
    var d= new Date();
    d.setTime(etime);
    console.log('Date in ms: '+d.toUTCString());
    console.log('Day of week: '+d.getDay());


  • 9.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Sep 01, 2016 10:27 AM

    Hi Jason, 

    I apologize for being a complete Java Noob. 

    Obviously, it's not as simple as copying and pasting your code into the Java script? 

    There is in fact no script currently on my form. 

     

    So I have started a new script

    The script below

     

     

     

    {
    checkFrmData: function() {
    ca_fd.js.displaymydate();
    },

    displaymydate: function() {
    var etime=ca_fdGetDateFieldValueInMillis(ca_fd.formId,'date_1')
    var d= new Date();
    d.setTime(etime);
    ca_fdGetDateFieldValueInMillis(ca_fd.formId,'date_1')
    console.log('Day of week: '+d.getDay());
    }
    }


     

    The function is then called displaymydate in the OnChange date field

     

     

    As per below pic, now every time I change the date it gets written into the console log.

    So it looks like I'm getting closer. 

     

    How would I then pass this through to ITPAM?

    Is it possible to pass the value in the console log into the text field below the date every time the value of date changes?

    If I hide this field from the user, Catalog will then still pass through the day number into ITPAM for further processing, after submission?

     

     

     

     



  • 10.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Sep 01, 2016 11:42 AM

    No worries, James. I just use the console log for debugging/testing, so instead of writing out to the console you can just pass the day of week into a hidden text field similar to the following:

     

    ca_fdSetTextFieldValue(ca_fd.formId,'day',d.getDay());

     

    And as getFormRateItemValues does return hidden form fields/values you can then leverage that field in your PAM process.

     

    For more information on the Catalog predefined JavaScript functions (like ca_fdSetTextFieldValue) I would recommend taking a look at Administration > Tools > Links > Form Designer JavaScript API.



  • 11.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Sep 01, 2016 12:20 PM

    Jason, 

    You are an absolute champion. 

    Thanks so much, this is exactly what I was looking for. 

     

     

    Directing me to this link

    Administration > Tools > Links > Form Designer JavaScript API

    has opened my eyes 



  • 12.  Re: ITPAM and CA Service Catalog - Epoch Time Format for date

    Posted Sep 01, 2016 12:33 PM

    Anytime James, glad to help!