Skip to content

js

js defines a custom JavaScript function which is executed. The function receives the userData and the object objects which can be used. The function can optionally return the following values
Parameters and functions
setFetchParam(key, value, treeName) Sets a fetch parameter that can then be used in a query constraint. Currently only supported in Maximo. Example below.
refreshTree(treeName) Updates the list of the given or current tree. Example below.
Promise.resolve() continues the menu chain without a payload
Promise.resolve(data) continues the menu chain with data as payload, where data can be an JavaScript object
Promise.reject(error) throws the given error
abort() cancels the menu chain

When nothing is returned the menu chain will continue without a payload.

Resolve without data

{
    "label": "JavaScript",
    "icon": "icon-fire",
    "action": "js",
    "actionValues": [
        {
            "js": "return Promise.resolve();"
        }
    ]
}

Resolve with data

{
    "label": "JavaScript",
    "icon": "icon-fire",
    "action": "js",
    "actionValues": [
        {
            "js": "const data = 'test'; return Promise.resolve(data);"
        }
    ]
}

Resolve with error

{
    "label": "JavaScript",
    "icon": "icon-fire",
    "action": "js",
    "actionValues": [
        {
            "js": "if(/*something work*/) {} else {return Promise.reject(error);}"
        }
    ]
}

Abort the menu chain

{
    "label": "JavaScript",
    "icon": "icon-fire",
    "action": "js",
    "actionValues": [
        {
            "js": "if(/*something not work*/) {abort()};"
        }
    ]
}

setFetchParam

{
    "label": "WAPPR",
    "icon": "icon-sun",
    "action": "js",
    "actionValues": [
        {
            "js": "return setFetchParam('SPECIAL', 'WAPPR').then(refreshTree);"
        }
    ]
},
{
    "label": "INPRG/WAPPR",
    "icon": "icon-sun",
    "action": "js",
    "actionValues": [
        {
            "js": "return setFetchParam('SPECIAL', ['INPRG', 'WAPPR']).then(refreshTree);"
        }
    ]
},
{
    "label": "Clear",
    "icon": "icon-brush",
    "action": "js",
    "actionValues": [
        {
            "js": "return removeFetchParam('SPECIAL').then(refreshTree);"
        }
    ]
},
{
    "label": "WAPPR and goto",
    "icon": "icon-sun",
    "action": "js",
    "actionValues": [
        {
            "js": "return setFetchParam('SPECIAL', 'WAPPR', 'my-tree-name').then(()=>{refreshTree('my-tree-name')});"
        }
    ],
    "then": {
        "action": "goto",
        "actionValues": [
            {
                "dstTree": "my-tree-name"
            }
        ]
    }
},

Query example

"query": {
    "constraint": "HISTORYFLAG=0 AND PARENT IS NULL AND STATUS IN ('${fetchParam.SPECIAL}')"
}

refreshTree

Refesh the current list

{
    "label": "JavaScript",
    "icon": "icon-fire",
    "action": "js",
    "actionValues": [
        {
            "js": "refreshTree()"
        }
    ]
}

Refesh the list for a given tree name

{
    "label": "JavaScript",
    "icon": "icon-fire",
    "action": "js",
    "actionValues": [
        {
            "js": "refreshTree('my-tree-name')"
        }
    ]
}