cancel
Showing results for 
Search instead for 
Did you mean: 

formatter on objectheader icon

Former Member
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

former_member227918
Active Contributor

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;
Former Member
0 Kudos

that was it 🙂 thanks

do you know why the formatter is called twice?

former_member227918
Active Contributor

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.

Answers (1)

Answers (1)

former_member227918
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.