Skip to Content
avatar image
Former Member

formatter on objectheader icon

hi

i have an objectheader which looks like this:

<ObjectHeader
	id="objectHeader"
	intro="{Supplier}"
	title="Business area: {BusArea}"
	icon="{
		path: 'DueDate',
		formatter: '.formatter.iconExpired'
	}"
	number="{PriceIBTW}"
	numberUnit="{Valuta}">

so i want the icon to change depending on the DueDate. my formatter looks like this:

iconExpired : function(oValue) {
	var dd = oValue.getDate();
	var mm = oValue.getMonth() + 1; //January is 0!
	var yyyy = oValue.getFullYear();
	var idueDate = (yyyy * 10000) + (mm * 100) + dd;
	var today = new Date();
	dd = today.getDate();
	mm = today.getMonth() + 1; //January is 0!
	yyyy = today.getFullYear();
	var iToday = (yyyy * 10000) + (mm * 100) + dd;
	if (idueDate < iToday) {
		return "sap-icon://error";
	} else {
		return "";
	}
}

but my oValue in the formatter seems to be null, but when i use the DueDate in my object header, for example in the intro, it displays on the screen nice and smooth. i don't understand what i'm doing wrong, can you guys help me?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 13, 2017 at 08:49 AM

    formatter function might be called twice, and first time you may get null,

    put your code inside a condition, like below and check if its working.

    if(oValue != null){
      // your code here
    }

    something like this,

    var sIcon = "";
    if (oValue != null) {
        var dd = oValue.getDate();
        var mm = oValue.getMonth() + 1; //January is 0!
        var yyyy = oValue.getFullYear();
        var idueDate = (yyyy * 10000) + (mm * 100) + dd;
        var today = new Date();
        dd = today.getDate();
        mm = today.getMonth() + 1; //January is 0!
        yyyy = today.getFullYear();
        var iToday = (yyyy * 10000) + (mm * 100) + dd;
        if (idueDate < iToday) {
            sIcon = "sap-icon://error";
        }
    }
    return sIcon;
    Add comment
    10|10000 characters needed characters exceeded

  • Apr 13, 2017 at 08:13 AM

    check console if any errors.

    what is the data type of 'DueDate' ? is this datetime ?

    actually icon is expecting string, ultimately from formatter it is coming as string only but this may be a check. check if datatype is causing issue.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      this is the error i get in the debugger:

      before this error nothing unusual.

      type of oValue is datetime. here is a screenshot from the debugger in another formatter where i pass the exact same value.

      the type is also not the problem. when i pass the supplier(which is a string) oValue is still null.

      thanks for the fast reply btw.

      code2.png (19.4 kB)
      code1.png (5.5 kB)