Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

RPE Script expression Java code variable

Hello, in RPE I want to format the date of a field from the ISO8601 format to a more readable format.


RPE provides an example java script to do this. I used this script and put it into the script expression field as per the attached image. The code works fine when I click the "Test Script" button and manually enter the date. It also works fine when I uncomment the first line of the code to assign a date to "modified". However, I want the date to be inherited dynamically from the datasource. But when I do this, I get an error that says the date is blank. 

How can I indicate that the date should come from the "modified" variable? This variable should not be blank.

edit - I do not have enough "reputation points" to include a helpful image for my question. So instead here is the code.

It may be unclear from just the code, but the variable "modified" is from $47 - datasource\artifact\colaboration\modified

*********
//modified = "2018-05-15T16:11:06.363+0000"; 

       var currDtFmt = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
       var curDt = currDtFmt.parse(modified);

var expDtFmt = new java.text.SimpleDateFormat("MM-dd-yyyy");
var dateString = expDtFmt.format(curDt).toString();
dispaly = dateString;

************




0 votes


Accepted answer

Permanent link

The formatting pattern returned by DNG fails to match and hence it is not working. Please try using the following Script Expression (that uses only date part from "modified" value returned from DNG):

var currDtFmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
var curDt = currDtFmt.parse(modified.substring(modified, modified.indexOf("T")));
var expDtFmt = new java.text.SimpleDateFormat("MM-dd-yyyy");
var dateString = expDtFmt.format(curDt).toString()

dateString;

Also, it is good to have this code within try-catch block.

Erik Herrmann selected this answer as the correct answer

0 votes


One other answer

Permanent link

 Had to change one line, but otherwise it worked.


should have been 
   display = datestring;


Thanks so much for the help!

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,940
× 332

Question asked: Oct 11 '19, 10:02 a.m.

Question was seen: 2,585 times

Last updated: Oct 16 '19, 9:49 a.m.

Confirmation Cancel Confirm