Skip to Content

Add resource/file/function to project at runtime

Feb 15 at 06:00 PM


avatar image

Hi Friends,

let say I have this as a string:

sap.ui.define([], function() {
    "use strict";
    return {
        testFunc: function() {

Now I want to call the above function "testFunc()" from my controller, like:

function(Controller, Function) {
    "use strict";
    return Controller.extend("CONT", {
        onInit: function() ;

But I get only at runtime the above string. So I would think. I create a resource(file.js) at runtime, put the string in there and call the function. But I have no idea how to manage this. I tried with sap.ui.define("functionjs") and then functionjs = string above. And I can find the functionjs in the controller, but I can not call the function testFunc().

Is there a way to manage this?

Rg. Joerg

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

3 Answers

Jun Wu Feb 16 at 12:42 PM

can you tell a bit background?

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

Hi, Jun

it should working like this.

The developer has an editor. In this editor he is writing the function code. Like above. When he is finished, the code is written to the backend. When the application is starting, the code will fetched from the backend and proceed in frontend. So only at this time I know the code and have to run it dynamically. An furthermore, I need the possibility to debug. So I need to load the whole script file.


what's the point?

Jun Wu Feb 15 at 07:07 PM

what you are designing?

10 |10000 characters needed characters left characters exceeded
Jun Wu Feb 15 at 07:08 PM
sap.ui.define([],function(){"use strict";return{

if that piece is stored in backend statically. why not just put them in your web app.

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

Because it can change. You can have several function in there. And this will defined at runtime.