How to use entity Data in javascript code.

How to use entity Data in javascript code.

  

I define the value as below in javascript code.

var list = {
    nodes : [
        { id : "a1", group : 0 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "a2", group : 0 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "a3", group : 0 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "a4", group : 0 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "a5", group : 0 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "a6", group : 0 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "a7", group : 0 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b1", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b2", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b3", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b4", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b5", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b6", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b7", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b8", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b9", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
        { id : "b10", group : 1 , info : ["aaa", "bbb", "ccc", "1.0.0"] },
    ],
    links : [
        { source : "a1", target : "a2", value : 5, level : 1, color : "red" },
        { source : "a1", target : "a3", value : 5, level : 1, color : "gray" },
        { source : "a1", target : "a4", value : 5, level : 2, color : "gray" },
        { source : "a1", target : "a5", value : 5, level : 3, color : "red" },
        { source : "a1", target : "a6", value : 5, level : 3, color : "gray" },
        { source : "a1", target : "a7", value : 5, level : 3, color : "gray" },
        { source : "a1", target : "b1", value : 5, level : 1, color : "red" },
        { source : "a1", target : "b2", value : 5, level : 1, color : "gray" },
        { source : "a1", target : "b3", value : 5, level : 1, color : "gray" },
        { source : "a1", target : "b4", value : 5, level : 1, color : "red" },
        { source : "a1", target : "b5", value : 5, level : 1, color : "gray" },
        { source : "a1", target : "b6", value : 5, level : 2, color : "gray" },
        { source : "a1", target : "b7", value : 5, level : 2, color : "gray" },
        { source : "a1", target : "b8", value : 5, level : 2, color : "gray" },
        { source : "a1", target : "b9", value : 5, level : 3, color : "gray" },
        { source : "a1", target : "b10", value : 5, level : 3, color : "gray" },
    ]
};


I want to use the value from not Javascript code but Entity.

I could add the value to Entity, but I don't know how to use the value in Entity in Javascript of Block property.


I'm sorry not to be good at English...

If your Javascript is placed in an Expression, then you can build it with standard string concatenation, for instance:

"window.alert('" + SomeEntity.SomeAttribute + "')";"

Jorge Martins wrote:

If your Javascript is placed in an Expression, then you can build it with standard string concatenation, for instance:

"window.alert('" + SomeEntity.SomeAttribute + "')";"


Thank you for your reply.

I write javascript in Web Block property.

Hi Toshiya Kirihata,

As far as I know you cannot write dynamic JavaScript on the JavaScript property of a Web Block or Web Screen.

You will need to write your static JavaScript on the JavaScript property, and the dynamic part you will have to do via Expressions (with their Escape Contents property set to No) either in Web Blocks or Web Screens

Hi Toshiya,

What are you going to do? Can you explain it more?

Solution

hi Tos,

Given: an Entity, say it Students

Find: Javascript to call that entity's record:

Cookbook:

1. Manage Dependency:

2. in the screen action (OK button action), call the RunJavaScript action 

where:

Note : we need to sanitize the literal part of the javascript, not all javascript as it makes error (no javascript executed)

and

and v_str is a local variable in that action.

3. Try It

regards,

IB

Solution

There are multiple ways you could do this, for instance expose a rest webservice which takes an Id, call that webservice in javascript using ajax and append the data to your list.

I Box wrote:

hi Tos,

Given: an Entity, say it Students

Find: Javascript to call that entity's record:

Cookbook:

1. Manage Dependency:

2. in the screen action (OK button action), call the RunJavaScript action 

where:

Note : we need to sanitize the literal part of the javascript, not all javascript as it makes error (no javascript executed)

and

and v_str is a local variable in that action.

3. Try It

regards,

IB


Hi I Box,

Thank you for your polite description!!

I try it.