It's all about the answers!

Ask a question

RPE Script expression Java code variable


Erik Herrmann (1515) | asked Oct 11 '19, 10:02 a.m.
edited Oct 11 '19, 5:57 p.m. by Fariz Saracevic (904613)

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;

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




Accepted answer


permanent link
Subramanya Prasad Pilar (4.6k16) | answered Oct 16 '19, 8:04 a.m.

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

One other answer



permanent link
Erik Herrmann (1515) | answered Oct 16 '19, 9:49 a.m.

 Had to change one line, but otherwise it worked.


should have been 
   display = datestring;


Thanks so much for the help!

Your answer


Register or 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.