Skip to Content
0

formatter on objectheader icon

Apr 13, 2017 at 07:39 AM

40

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Akhilesh Upadhyay Apr 13, 2017 at 08:49 AM
1

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;
Show 2 Share
10 |10000 characters needed characters left characters exceeded

that was it :) thanks

do you know why the formatter is called twice?

0

first time called while rendering and second time while binding the table, as expected for table control i guess, for normal control it should not be.

1
Akhilesh Upadhyay Apr 13, 2017 at 08:13 AM
0

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.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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)
0