JavaScript

1. General

With JavaScript script, you can expand the functionality of Intrexx. Click here for more information about where the JavaScript editor can be found and used in the Intrexx Portal Manager. The following links provide additional helpful information about using JavaScript in Intrexx:
The corresponding, sufficient programming knowhow is required to use JavaScript in Intrexx. Please note that United Planet is not liable for errors, loss of data or security flaws that arise as a result of incorrect JavaScript scripts.

2. Libraries




In the JavaScript script editor, you can access the Intrexx Library for Mobile Devices and Intrexx Standard Library on the Libraries tab. If you select an entry in the library, you can access these buttons at the bottom right of this area:

Show description
Shows the description of the currently selected function with an example script.

Open link
Links to the corresponding page that provides more information. The page that opens also shows the classes, interfaces, methods or properties that the currently selected function can be used for.

3. Intrexx Library for Mobile Devices

3.1. Read and write values

3.1.1. Write in a view/edit field

Writes a value in a view field or edit field.

Example

Browser.setValue(getElement("F28BA7351E3C8F5123880548CFA72B64566A1433"), "Some text");

Snippet

Browser.setValue(oHtml, strValue);

3.1.2. Read a view/edit field

Read a value from a view or edit field.

Example

Browser.getValue(getElement("F28BA7351E3C8F5123880548CFA72B64566A1433"));

Snippet

Browser.getValue(oHtml);

3.2. Ajax

3.2.1. Load a JavaScript file

Loads a JavaScript file using the specified path.
Loader.loadJsFileOnDemand(strFileName)

4. Intrexx Standard Library

4.1. Ajax

4.1.1. Trigger a UserWorkflowEvent

Triggers a process through a UserWorkflowEvent.
Parameter: GUID of the UserWorkflowEvents.
triggerUserWorkflowEvent("");

4.1.2. Trigger a UserWorkflowEvent with request parameters

Triggers a process through a UserWorkflowEvent with additional request parameters.

Parameter 1: The GUID of the UserWorkflowEvent
Parameter 2: JSON list with parameters

Example

triggerUserWorkflowEvent("BE2514445AC5C88F74891F9B296C283AC06F366C",  {qs_param: paramValue});

Snippet

triggerUserWorkflowEvent("",  {});

4.1.3. Trigger a UserWorkflowEvent and process the result

Triggers a process through a UserWorkflowEvent and checks the status of the process run.
Parameter: The GUID of the UserWorkflowEvent
$.when(triggerUserWorkflowEvent("",  {}))
.done(function()
	{
		alert("done")
	}
)
.fail(function()
	{
		alert("failed")
	}
);
return true;

4.1.4. Call a Velocity file to retrieve XML (Portal)

Send a form to the server, then send XML from a VM file back to the browser and write it in a edit field.
var el = getElement("GUID_STATIC_TEXTFIELD");
ajaxVTL("internal/system/vm/custom/.vm", {
    dataType: 'xml',
    data: {
        fr_param1: Browser.getValue(getElement("GUID_FORM_FIELD"))
    },
    success: function (data) {
        Browser.setValue(el, data);
    },
    ixWaitAnim: {
        element: el,
        type: "overlay"
    }
});

4.1.5. Call a Velocity file to retrieve text (Application)

Send form data and write it in a edit field. The form value in this example can be read in the application VM file via $Request.get("fr_param1").
var el = getElement("GUID_STATIC_TEXTFIELD");
ajaxAppVTL(".vm", {
    dataType: 'text',
    data: {
        fr_param1: Browser.getValue(getElement("GUID_FORM_FIELD"))
    },
    success: function (data) {
        Browser.setValue(el, data);
    },
    ixWaitAnim: {
        element: el,
        type: "overlay"
    }
}, el);

4.1.6. Call a Velocity file to retrieve JSON (Application)

Create a custom JSON response within a VM file (from the application package) and send it to the browser.
var el = getElement("GUID_FROM_ANY_CONTROL");
ajaxAppVTL(".vm", {
    dataType: 'json',
    success: function (data) {
        alert(data.myJSONAnswer);
    },
    ixWaitAnim: {
        element: el,
        type: "overlay"
    }
}, el);


4.1.7. Call a Groovy file to retrieve JSON (Portal)

Calls a global Groovy file via Ajax and returns the response to the browser.
// Path to Groovy file
ix.ajax().requestGroovy('groovy/.groovy', {
    dataType: "json",
    data: {
        "param_a": "1",
        "param_b": "2"
    },
    success: function (data) {
        alert(data);
    }
});

4.1.8. Call a Groovy file to retrieve JSON (Application)

Calls an application Groovy file via Ajax and returns the response to the browser.
var el = getElement("GUID_FROM_ANY_CONTROL");
ix.ajax().requestAppGroovy("file.groovy", {
    dataType: "json",
    data: {
        "param_a": "1",
        "param_b": "2"
    },
    success: function (data) {
        alert(data);
    },
    ixWaitAnim: {
        element: el,
        type: "overlay"
    }
}, el);

4.2. Calculations

4.2.1. Simple arithmetic calculations

Calculates the result of two values from HTML controls using an operator and writes the result in an HTML control.

Example

calculate(getElement("F28BA7351E3C8F5123880548CFA72B64566A1421"), getElement("80467069EA61BD786CFFEB508786723D6451F2F5"),
"+", getElement("B52A9E9FC555A820984E63DECF13BCAA33E308CD"));

Snippet

calculate(oHtmlNumber1, oHtmlNumber2, strOperator, oHtmlResult);

4.2.2. Calculate duration

Calculates the difference between two HTML "date & time" controls and returns it as string formatted for example as "2 days 3 minutes".

Example

getLocalDurationString(getElement("4E48F310711C446B4B04752A6B3239900D49F3A0"),getElement("E13A41C114E8754574DEA9767F505DDE3491C89A"));

Snippet

getLocalDurationString(oHtmlDate1, oHtmlDate2);

4.3. Notifier

4.3.1. Simple notifier

Displays a simple status message at the bottom right of the browser. The methods "warn" or "error" can be used instead of "notify".
Notifier.status.notify("Changes applied.");

4.3.2. Display notifier aligned to an HTML element

Displays a simple status message beneath an HTML element (bottom left corner). The method "error" can be used instead of "notify".
Notifier.element.notify(getElement(), "EXAMPLE_TEXT");

4.4. Buttons

4.4.1. Set duration to a whole day

Sets two date fields so that they form the duration of a whole day: dateFrom 00:00 a.m., dateTo 00:00 a.m. next day.

Example

(executable in an onclick() event of a checkbox):
setFullDays(getElement("123401F1E55C9A193BE6EC4091B45C6A5A6C8154"), getElement("DD2E01F1E55C9A193BE6EC4091B45C6A5A6C8154"), getElement("4D0708BDECC7D088613F818CE1B09B8D812F5750") );

Snippet

setFullDays(oHtmlCheckbox, oHtmlDateFrom, oHtmlDateTo);

4.5. Tables

4.5.1. Color columns and rows (number values)

Colors rows and columns in a view table based on a number value. The value of the color can be set by hexadecimal value or by name. The following elements can be colored: "row" = whole row (tr), "cell" = whole cell (td), "span" = text of cell (span)

Example

(color all rows, where value in field viewcontrolD54BA2DD is greater than 10):
inking("viewcontrolD54BA2DD", ">", 10, "#008000", "row");

Snippet

inking(strControlName, strOperator, compareValue, strColor, colored);

4.5.2. Color columns and rows (date values)

Colors rows and columns in a view table based on a date value. Values can be compared with the current date ("date") or with the current and time ("datetime"). The value of the color can be set by hexadecimal value or by name. The following elements can be colored: "row" = whole row (tr), "cell" = whole cell (td), "span" = text of cell (span).

Example

(colors all rows, where date value in field viewcontrolD54BA2DD is less than the current date):
inkingDate("viewcontrolD54BA2DD", "<", "date", "#008000", "row");

Snippet

inkingDate(strControlName, strOperator, dateType, strColor, colored);

4.5.3. Color columns and rows (string values)

Colors rows and columns in a view table based on a string value. The value of the color can be set by hexadecimal value or by name. The following elements can be colored: "row" = whole row (tr), "cell" = whole cell (td), "span" = text of cell (span).

Example

(colors all rows, where status in field viewcontrolD54BA2DD equals "done"):
inkingString("viewcontrolD54BA2DD", "==", "erledigt", "#008000", "row");

Snippet

inkingString(strControlName, strOperator, strValue, strColor, colored);

4.5.4. Get row

Returns the parent node (the row) of the given node.
getRow(node)

4.5.5. Get column

Returns the parent node (the column) of the given node.
getCol(node)

4.6. Read and write values

4.6.1. Write in a view/edit field (with ID)

rites a value in a view field or edit field that is referenced using its DOM ID ("ID" attribute of the HTML element).

Example

setTextValueById("ID_labelcontrol900CB1AB", "Some text");

Snippet

setTextValueById(strHtmlId, strValue);

4.6.2. Write in a view/edit field

Writes a value in a view field or edit field.

Example

Browser.setValue(getElement("F28BA7351E3C8F5123880548CFA72B64566A1433"), "Some text");

Snippet

Browser.setValue(oHtml, strValue);

4.6.3. Read a view/edit field (with ID)

Read a value from a view field or edit field that is referenced using its DOM ID ("ID" attribute of the HTML element).

Example

getTextValueById("ID_labelcontrol900CB1AB");

Snippet

getTextValueById(strHtmlId);

4.6.4. Read a view/edit field

Read a value from a view field or edit field.

Example

Browser.getValue(getElement("F28BA7351E3C8F5123880548CFA72B64566A1433"));

Snippet

Browser.getValue(oHtml);

4.6.5. Copy text to clipboard

Copies text to to clipboard. If sending to clipboard is disabled for security reasons, a tooltip that the text can be copied from will appear instead. Parameters:

param1:
Text or action control. In case of an action control, its target link URL is copied to clipboard.

param2:
Optional parameter as list with following possible values:
strMsgTitle - Title of feedback tooltip.
strMsgBody - Text of feedback tooltip, if text was successfully copied to clipboard.
bFallback - true (default) or false. If text could not be copied to clipboard and bFallback is set to true, the text defined in strMsgBody is displayed.
iTextHeight - Row height within tooltip (default: 1).
iTextWidth - Width of tooltip (default: 50).
strTextStyles - CSS definitions for tooltip.


Example

Helper.sendToClipboard("Hallo Welt!", {strMsgTitle: "Clipboard", strMsgBody: "Text copied to clipboard", bFallback: true, iTextHeight:1, iTextWidth:50};
Helper.sendToClipboard(getElement("56C159AEECD062FC3B273F0E999A67FA842D3FB8").oUp);

Snippet

Helper.sendToClipboard(param1, param2);

4.7. Format values

4.7.1. Float from locally formatted string

Parses a locally formatted string into a float (number object).

Example

getFloatByLocalString("1.234");

Snippet

getFloatByLocalString(strValue);

4.7.2. Float string from locally formatted string

Parses a locally formatted string into a string in float format (for example 1.234,56 -> 1234.56).

Example

getFloatStringByLocal("1.234,56");

Snippet

getFloatStringByLocal(strValue);

4.7.3. Integer from locally formatted string

Parses a locally formatted string into an integer (number object).

Example

getIntegerByLocalString("1.234");

Snippet

getIntegerByLocalString(strValue);

4.7.4. Integer string from locally formatted string

Parses a locally formatted string into a string in integer format (for example 1,234 -> 1234).

Example

getIntegerStringByLocal("1.234");

Snippet

getIntegerStringByLocal(strValue);

4.7.5. JavaScript date from HTML control

reates a JavaScript date object from a "date", "time" or "date & time" HTML control.

Example

getDateObject(getElement("A84E5E7F9EA9ED1A829DB98DBF5459F59961FA3B"));

Snippet

getDateObject(oHtml);

4.7.6. JavaScript number object from HTML control

Creates a JavaScript number object from an "integer", "float" or "currency" HTML control.

Example

getNumberObject(getElement("5F7S5E7F9EA9ED1A829DB98DBF5459F59961FA3B"));

Snippet

getNumberObject(oHtml);

4.7.7. Locally formatted string from a number string or a datetime string

Creates a locally formatted string from a number string or a datetime string. The parameter "oHtml" creates a reference to an "integer", "float", "currency" or "datetime" HTML input control. This HTML control defines type and formatting properties for the given value. "strValue" defines the value to be formatted.

Example

toLocalString(getElement("DDB279D4974A17DB27A89F58DB36F7BF4E10DA13"),"123.45");

4.7.8. Locally formatted string from a date

Formats a JavaScript date (date object) as a string according to the formats (locations) configured in the portal.

Transfer parameter: JS date Return value: The date formatted as a string (based on the user's location)
upDateControl.toLocalFormat(jsDateObject);
toLocalString(oHtml, strValue);

4.7.9. Format a string and write it in an HTML control

Creates a locally formatted string from a number string or a datetime string and writes the result in an HTML input control.

toLocalString(oHtml, strValue)
oHtml - Reference to an "integer", "float", "currency" or "datetime" HTML input control. This HTML control defines type and formatting properties for the given value. The result is written in this HTML input control. strValue - String to format

Example

writeLocalString(getElement("DDB279D4974A17DB27A89F58DB36F7BF4E10DA13"),"123.45");

Snippet

writeLocalString(oHtml, strValue);

4.7.10. Currency from locally formatted string

Parses a locally formatted string into a currency (number object).

Example

getCurrencyByLocalString("1.234");

Snippet

writeLocalString(oHtml, strValue);

4.7.11. Currency string from locally formatted string

Parses a locally formatted string into a currency value as string (for example 1,234.56 -> 1234.56).

Example

getCurrencyStringByLocal("1.234,56");

Snippet

getCurrencyStringByLocal(strValue);

4.8. WebSockets

The JavaScript methods in connection with WebSockets offer the possibility to subscribe and unsubscribe to messages (topics).

ix.websocket

4.8.1 Start subscribing to a topic

Note: Please note that the following examples are not designed for IE11.

Example 1:
const mySubscriber = await ix.websocket.subscribeToTopic("D00F000000000000000000000000000000000000", {
   onmessage: (data) => {
      console.log(data);
   }
});
Example 2:
const mySubscriber = await ix.websocket.subscribeToTopic("D00F000000000000000000000000000000000000", {
   key: "key1",
   onmessageJSON: (data) => {
      console.log(data);
   },
   onerror: (error) => {
      console.log(error);
   },
   onclose: (event) => {
      console.log(event);
   }
});
Snippet:
ix.websocket.subscribeToTopic(topic, subscriber [, websocketAlias])
ix.websocket.html#ix.websocket.subscribeToTopic__anchor

4.8.2 Stop subscribing to a topic

Note: Please note that the following examples are not designed for IE11.

Example 1:
ix.websocket.unsubscribeFromTopic(mySubscriber)
Example 2:
ix.websocket.unsubscribeFromTopic("key1")
Snippet:
ix.websocket.unsubscribeFromTopic(subscriber [, websocketAlias])
ix.websocket.unsubscribeFromTopic__anchor

4.9. Input required

Checks the stated input control as if "Input required" were set OR checks all controls of a stated form group where "Input required" was set. Optionally, an alternative text can be defined as the second parameter. This text is displayed instead of the predefined text in case of errors.

Example

checkRequired(getElement("E94A9FBDADD46039BB62F76870E1EC57C226C6DC"), "Alternative text");

Snippet

checkRequired(oHtml,strMessage);

4.10. Compare date

Compares the value of a date control ("date", "time" or "datetime") with the current date. Can be used for input and view controls. For view controls the expert attribute "jsobject = true (Boolean)" has to be set.

Example

dateComparedToNow(getElement("5F7S5E7F9EA9ED1A829DB98DBF5459F59961FA3B"));


Possible return values:
-1 if an error occurred or input field is empty.
0 if value is less than current date.
1 if value equals current date.
2 if value is greater than current date.

Snippet

dateComparedToNow(oHtmlDate);

4.11. Add or subtract time interval

Adds or subtracts an interval to/from a given JavaScript date object.
Possible values:
"ms" - milliseconds / "s" - seconds / "mi" - minutes / "h" - hours / "d" - days / "mo" - months / "y" - years

Example

var dtNow = new Date();
var dtAdd1 = dateAdd("d", 1, dtNow); // adds 1 day to current date
var dtAdd2 = dateAdd("h", -2, dtNow); // subtracts 2 hours from current date
dateAdd(typeOfInterval, intValue, oHtmlDate);

4.12. Open page of an application

Executes an application request and opens an application page in a new window.

Example

makeAppRequest("5C9AA563556C7A98CD03AAFAE9E93EC13B6EBB07", "8875BAC49802DC90A9FE41F5114D8F1E28036891", "1", false, false, false);

Snippet

makeAppRequest(strApplicationGuid, strPageGuid, strRecId, false, false, true);

4.13. Disable JavaScript compression

By inserting this comment, the compression of JavaScript files can be deactivated, i.e. for debugging.
// compress = false

4.14. Access language constants

Example for accessing a global language constant:
ix.text.i18n.get('WIDTH')

Example for accessing a language constant from an application:
ix.text.i18n.getByApp('AB4B031834F042FCADB595DF1923B768C7773F00', 'SHARE_FEED_MORE_COMMENTS')
ix.text.i18n