Skip to Content

Validate SystemDateTime in groovy script used in SAP CPI

Hi,

I'm trying to get the system datetime by declaring this in content modifier and then getting that value into groovy script for a validation.

// Declaring the date in CM

datetimeformat.png

format used is :

${date:now:yyyy-MM-dd'T'HH:mm:ss'Z'}

In the groovy script I have declared as below.

def today = map.get("Today");

it.employmentNav.EmpEmployment.endDate.text() < today

the value for 'endDate' from EC comes as '2020-02-16T00:00:00.000' .

So when I'm trying to execute the iflow, this is not recognizing the correct date format, somewhere its going wrong,

can you please help on this?

datetimeformat.png (14.7 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on May 12 at 08:10 AM

    Hi Sethuraman

    You don't need to store the system date in a Property using a Content Modifier to achieve this. Do something like the following in your script:

    def today = new Date()
    def endDate = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS", it.employmentNav.EmpEmployment.endDate.text())
    
    if (endDate < today) {
        // The end date has already occurred.
    }

    This turns the contents of the EC field into a Date object, and compares it to the current date and time.

    Regards,

    Morten

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Sethuraman Tamilarasan

      That would probably be something like this:

      def today = new Date()
      xmlData.EmpJob.findAll {
        it.emplStatusNav.PicklistOption.picklistLabels.PicklistLabel.label.text() == 'Terminated' && 
          Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS", it.employmentNav.EmpEmployment.endDate.text()) < today
      }.each {
        it.replaceNode{}
      }

      But getting the specific script to run is your task. It is never a good idea to copypaste code, you don't fully understand, into a solution you are responsible for maintaining.

      Regards,

      Morten

  • Posted on May 12 at 06:21 AM

    Hi Sethuraman,

    Could you assign the endDate to a Date type variable.

    Currently you are trying to compare text with Date type which might be causing the issue.

    Please refer below answer by Sriprasad Shivaram Bhat

    https://answers.sap.com/questions/12931868/date-difference-in-days-in-sap-cpi.html?childToView=12935540#answer-12935540

    hope this helps!

    thanks and regards,

    Praveen T

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.