Question

Auto formatting time as XX:XX

I have one requirement like when i enter the time as 1005 it should automatically format as 10:05. Can anyone explain how to implement this?

Thanks in Advance !!

Correct Answer
September 30, 2019 - 3:34pm

Hello @gubbas78,

I am just adding some more details to @Rachit_Agarwal reply.

I assume that you are taking input in text input field. 

1) Open the property configured on the input field.

2) Go to advanced tab of the property and create own edit input as shown below

3) create a EditInput as shown below with code.

4) The code of edit input looks like

if(theValue.length()==4){
  try{
    Integer.parseInt(theValue);
    theValue = theValue.substring(0,2)+":"+ theValue.substring(2,4);
  }catch(NumberFormatException e){
    //nothing
  }
    
}

5) Once saved, Go back to configuration of the control and its action tab then configure, Referesh-This-Section as shown below.

6) Run the scenario.

Scenario 1 : (unsuccessful scenario)

Scenario 2 : (unsuccessful scenario)

Scenario 3 : (successful scenario)

Hope this helps !

Please feel free to post for any follow-up questions.

Thank you,

Regards, Cherb.

Comments

Keep up to date on this post and subscribe to comments

September 30, 2019 - 11:55am

You can use the below code in Edit Input Rule.

theValue = theValue.substring(0,2)+":"+ theValue.substring(2,4);

Please make sure we perform validation.

 

Pega
September 30, 2019 - 3:34pm

Hello @gubbas78,

I am just adding some more details to @Rachit_Agarwal reply.

I assume that you are taking input in text input field. 

1) Open the property configured on the input field.

2) Go to advanced tab of the property and create own edit input as shown below

3) create a EditInput as shown below with code.

4) The code of edit input looks like

if(theValue.length()==4){
  try{
    Integer.parseInt(theValue);
    theValue = theValue.substring(0,2)+":"+ theValue.substring(2,4);
  }catch(NumberFormatException e){
    //nothing
  }
    
}

5) Once saved, Go back to configuration of the control and its action tab then configure, Referesh-This-Section as shown below.

6) Run the scenario.

Scenario 1 : (unsuccessful scenario)

Scenario 2 : (unsuccessful scenario)

Scenario 3 : (successful scenario)

Hope this helps !

Please feel free to post for any follow-up questions.

Thank you,

Regards, Cherb.

October 1, 2019 - 3:39am
Response to cherb

Thank You. It worked for me.

 

 

Pega
October 7, 2019 - 11:17am
Response to gubbas78

I am glad that it worked for you. Request you to mark it as "Correct answer" to let the other developers to point to right answer when this post pop out in their search.

Mod
October 7, 2019 - 12:21pm

Hello,

We have marked this post as Answered.

Thank you.

Lochana | Community Moderator | Pegasystems Inc.