cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Formatting Object Status value

Former Member
0 Likes
2,401

I'm using the sap.m.ObjectStatus as part of my status display on a given agregated list:

in view.js:

var curstat = new sap.m.ObjectStatus({

                                                   //text:  "{CountDate}",

                                                   //text: oController.formatDate('{CountDate}'),

                                                   state: "Success",

                                                   text: {

                                                        parts:[{path:'CountDate'}],

                                                        formatter: 'oController.formatterCountDate'

                                                   }

                                                });

snippet in the controller.js, the format of the CountDate value is, yyyy-mm-ddT00:00:00.  goal is to remove the time part leaving only YYYY-MM-DD.  I don't get any exception thrown and the date does show just not in the format I want.  I feel I'm close but just can't get figure out what I may be over looking.  Thanks in advance for the help.

formatterCountDate:function(t) {

                  try {

                  var d = new Date();

                  var T = new sap.ui.model.type.Date( {

                                                     source : {

                                                     pattern : "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

                                                     },

                                                     pattern : "yyyy,MM,dd",

                                                     style : "medium"

                                                     });

                  d = T.formatValue(t, "string");

                  var D = new Date(d);

                  return D

                  }//try

                  catch(error) {

                    alert(error.message);

                  }

},

Accepted Solutions (0)

Answers (2)

Answers (2)

naveenraj_sap
Active Participant
0 Likes

Hi Jay, Is your problem solved?

Former Member
0 Likes

Hi Naveen.  Not really.  But your code recommendation does work.  Issue now is that when the field being used in the ObjectStatus is empty, seems to return a date with year 1969. 

naveenraj_sap
Active Participant
0 Likes

Hi Jay, What is the data format you have in your oData model?

Can you post the data which you are sending to the formatterCountDate(), function.

Also in the formatterCountDate() function, pls have an intial condition like,

if((value!=null) && (value!=""))

{

/* format logic here */

}

Try this and let me know.

Former Member
0 Likes

Hi Naveen,  The format of the date coming in is, YYYY-MM-DDT00:00:00.  It does format the date when the result includes the date, I get the proper format.  It's when the record does not have a value in the countDate field, the return of empty string seems either the formatter is returning something other than just empty string and in this case, the date ends up being '1969'. 

Here's my formatter logic.  Thanks.

new sap.m.ObjectStatus({

                                                   state: "Success",

                                                   text: {

                                                        parts:[{path:'CountDate'}],

                                                        formatter: function(t) {

                                                  

                                                            try {

                                                                   

                                                   if(t != null || t != '0000-00-00') {

                                                                    var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: "yyyy-MM-dd"});

                                                                    return oDateFormat.format( new Date(t) );

                                                                    //return t;

                                                   }

                                                   else {

                                                    return "";

                                                   }

                                                  

                                                           }//try

                                                        catch(error) {

                                                                    alert(error.message);

                                                            }//catch

                                                        }//formatter

                                                  }

                                                });

naveenraj_sap
Active Participant
0 Likes

Hi Jay, as i mentioned in the previous thread,

You need to re-write the if condition if(t != null || t != '0000-00-00')  as,

if(t != null || t != '')

{

// you date pattern logic here

}


--Naveenraj.A

naveenraj_sap
Active Participant
0 Likes

Hi Jay, can you try with the below code.

Also make sure your CountDate propery in OData model has Edm.DateTime datatype.


formatterCountDate : function (value) {

  if((value!=null) && (value!="0000-00-00"))

  {

  if (value) {

  var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "yyyy,MM,dd"});

  return oDateFormat.format(new Date(value));

  }

else {  return value; }

  }

  else return "";

  }

Let me know if you face any issues.

--Naveenraj.

Former Member
0 Likes

Thanks Naveenraj.  This almost worked.  But it keeps returning with the year 1969.  tried to just pass value to oDateFormat.format but it comes back with:

'null' is not an object value.getDay.

Former Member
0 Likes

it seems like, when the date field is empty, even when I say " return ""; ", it forces it to have something and in this case, it returns 1969-12-13.  But the formatting works correctly; able to remove the time part.