Skip to Content
Technical Articles
Author's profile photo Jens Niemeyer

Creating a custom rule editor for CX in SAPUI5

SAP C4C comes with an internal rule editor for defining rules for validation/visibility of fields within the Key User Tool (KUT).

A simple rule could exists out of one line, e.g. the following rule defines, that the internal notes are  only enabled, if the ticket is in edit mode:


A simple rule in the CX rule editor, (c) Jens Niemeyer


The example of the rule is simply written in one line and even with a linebreak it is readable.


The challenge

When it comes to more complex scenarios for the rules, the rule have to match the following criteria:

  • all content is in “one line”
  • no line break within the rule
  • no comments or spaces, to make the rule readable


In the following screenshot you see a real rule, based on a customer requirement:


A complex rule (c) Jens Niemeyer.

So gues what the rule is doing? How it is working? How can you change the rule, if the customer does have new ideas?

The big gaps in the CX rule editor are:

  • not readable source code
  • to small textarea for your source code
  • no “pretty print” on your code.


To overcome this issue I build my own editor in SAPUI5.

  • All rule sources are saved in a “pretty printed” form in an Excel sheet or other *.txt Files
  • In the rule editor I copy and paste the code and edit it
  • with “copy to clipboard” I copy a C4C conform version into the clipboard, which I could paste in the original C4C rule editor

My editor is shown in next screenshot.

In the editor window (1), you can write your readable code.
This code should be saved in a version control system or directory for later changes.

With “Copy to clipboard” (2) you will get a CX conform version of the rule in your clipboard, which could be pasted in the CX rule editor.

To have access to the clipboard is is mandatory, that you run the HTML file locally (3) e.g. from your desktop.



My own offline rule editor, (c) Jens Niemeyer

If you like, you can copy my code from the section below, place it on your desktop and open it with a double click.

    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta charset="UTF-8">
    <title>Rule Editor Convertor by Jens Niemeyer</title>
    <script id="sap-ui-bootstrap"
    <script id="startpage" type="ui5/xmlview">

            <Page title="C4 Rule Converter">
			<Button press="pressBtn" icon="sap-icon://paste" text="Copy to clipboard" />
                		<c:CodeEditor type="javascript" 
                						height="80%" id="txt"
                   			<TextArea width="100%" enabled="false" id="newText"                   					
        sap.ui.getCore().attachInit(function () {
            "use strict";
            ], function (Controller) {
                return Controller.extend("${UI5_Namespace}.controller.${NAME}", {

                    pressBtn: function (oEvent) {
                    	let textToCopy =this.getView().byId("newText").getValue();

						async function copyToClipboard() {
						  try {
						    await navigator.clipboard.writeText(textToCopy);"Copied to clipboard");
						    // 2) Catch errors
						  } catch (err) {
						    console.error('Failed to copy: ', err);
"Failed to copy");

                    onUpdate: function (oEvent) {

                        var txt 		= this.getView().byId("txt").getCurrentValue();
                        var newText		= txt.replaceAll("\t", " ");
                        newText			= newText.replaceAll("\n", " ");
                        newText			= newText.replaceAll("\r", " ");
                        newText			= newText.replaceAll("  ", " ");
                        newText			= newText.replaceAll(" ", "");

            ], function (jQuery) {
                    viewContent: jQuery("#startpage").html()
<body class="sapUiBody" id="root"/>

(c) Jens Niemeyer, feel free to copy code and reuse it for your own needs



With this simple to use editor you can easily write powerful rules for the key user tool (KUT).

You can take the source code as a basis for a more complex App, where you could store all sources of your rules in a local directory (running the app locally, it should be possible to access the file system) ans store them in a version control system.

And perhaps SAP Development uses the code to enhance the KUT rule editor in the future.

I would really appriciate, if they

  • use the UI5 lib for color high lighting
  • enable a full screen dialog, to see as much as possible from the rules code

Feel free, to add comments or thougts on my simple approach.







Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Francisco Ruiz Garcia
      Francisco Ruiz Garcia


      I have created an idea requesting this editor in C4C 😀