cancel
Showing results for 
Search instead for 
Did you mean: 

Dependency issue with custom formatter

0 Kudos

Hello,

I was referring below link to use custom formatter in my application:

https://sapui5.netweaver.ondemand.com/docs/guide/0f8626ed7b7542ffaa44601828db20de.html

This works fine but I need to take a different approach as per my Application framework. So I did the following things as below:

1. Create a formatter file under a specific folder

(function() {

  'use strict';

  jQuery.sap.declare("mytravelandexpense.formatter.myGenericFormatter");

  mytravelandexpense.formatter.myGenericFormatter = {};

  mytravelandexpense.formatter.myGenericFormatter.concatenateObjDesc = function(o, d) {

  return 0 + ' -' + d;

  };

});

2. I have created a dependency in my controller as below:

jQuery.sap.require("mytravelandexpense.formatter.myGenericFormatter");

3. Next I have used this formatetter in my view :

text="{ parts:[{path: 'Model1>CostObjectID'}, {path:'Model2>Description'}], formatter:'mytravelandexpense.formatter.myGenericFormatter.concatenateObjDesc'}"

But in console I see, it says the formatter is not found.

Could you please help me to understand where I am doing the wrong.

- Thanks , Somnath

Accepted Solutions (0)

Answers (2)

Answers (2)

junwu
Active Contributor
0 Kudos

what's your folder structure and controller name

0 Kudos

Hello, Please find the folder structure of my custom formatter file:

myProject>Formatter>myGenericFormatter.js

Where mytravelandexpense is the namespace.

- Thanks, Somnath

ugurkaya
Active Participant
0 Kudos

Hey Somnath,

Could you capitalize all the formatter phrase into  "....Formatter.myGenericFormatter", since your folder name starts with capital.

Regards

Ugur

junwu
Active Contributor
0 Kudos

as other one mentioned. please make them match. it should be upper case.

0 Kudos

my bad, it is actually formatter not Formatter.

junwu
Active Contributor
0 Kudos

do u have other error in your console?

try this when u define your formatter

mytravelandexpense= mytravelandexpense||{};

mytravelandexpense.formatter=mytravelandexpense.formatter||{};

mytravelandexpense.formatter.myGenericFormatter = {};

0 Kudos

Dear,

I think I have placed either a very bad question or very hard question to answer Was expecting some help as I am stuck with this.

Will appreciate a reply/advice.

- Thanks , Somnath

ugurkaya
Active Participant
0 Kudos

Hey Somnath,

It looks correct though.

Do you have your "myGenericFormatter" placed correctly under the folder "formatter" in your root content ("mytravelandexpense") ?

Regards

Ugur

former_member185414
Active Contributor
0 Kudos

What is the name you have assigned to dependency in controller

Suppose in controller you have assigned  as below -

sap.ui.define([

  "sap/cdp/ums/managerequests/controller/BaseController",

  "mytravelandexpense/formatter/myGenericFormatter"

  ], function(BaseController, formatter) {

  "use strict";

  return BaseController.extend("<namespace>.Object", {

  formatter: formatter,





Change in view as below -


text="{ parts:[{path: 'Model1>CostObjectID'}, {path:'Model2>Description'}],

formatter:'.formatter.concatenateObjDesc'}"


BR.