Skip to main content
NICE CXone Expert
Expert Success Center

If statements in DekiScript

Use if statements, if/else statements, or if/not statements with DekiScript to display certain information when specific conditions exist.

If statement example

Create an if statement to tell an application what to do if a certain condition exists:

  1. Open a page in Edit mode.
  2. Copy the following code into a  DekiScript code block:
if(date.hours(date.now) >= 12) {
   template("Custom/Views/Header");
}
  1. Once you save the page, depending on the time of day, you may or may not see content.

Output: INTENTIONALLY NOT RENDERED

If/else statement examples

  • Add information to a document that only specific users can see.
  • Add information to a document that only appears in certain circumstances.

Display text for admin users when they visit a page, but display different text for non-admin users:

  1. Open a page in Edit mode.
  2. Copy the following code into a  DekiScript code block:
if (user.name == "Admin")
{
    "This information can only be seen by the admin. No other use user can see it.";
}
else
{
    "If you do not want non-admin users to see anything, just do not type anything between the quotation marks.";
}
  1. Once you save the page, depending on your viewing privileges, you will see one of the above texts:
If you do not want non-admin users to see anything, just do not type anything between the quotation marks.

Make sure that the "a" in Admin is capitalized.

For DekiScript to ignore  case, create a variable for user.name and add string.tolowerbefore the variable as in the following example:

var luser = string.tolower(user.name);
if (luser == "admin")
{
    "Hello, admin.";
}
else
{
    "You are not an admin.";
}

Evaluate a conditional expression, if the outcome of the expression is nil, false or 0, execute the block immediately following the if statement. Otherwise, execute the block following the optional else statement.

Different languages treat different values that are not a true/false boolean differently. In DekiScript false as well as nil and zero are logically false, while True and everything else (other than nil, false or 0) are treated as logically true.

To conditionally include a template:

if(date.hours(date.now) >= 12) {
   template("Custom/Views/Header");
}

Output: INTENTIONALLY NOT RENDERED

To conditionally emit one text or another:

if(user.anonymous) {
   "Welcome guest. Please register!"
} else {
   "Welcome back ".. user.name .. "!"
}

Output: Welcome guest. Please register!

If not statement example

  • Exclude or change information on a page for specific users.

Telling an application what to do if something does NOT equal something:

  1. Open a page in Edit mode.
  2. Copy the following code into a  DekiScript code block:
var x =25;
if (user.name != "Admin")
{
let x = 75;
}
x;
  1. Once you save the page, depending on your viewing privileges, you will see one of the above texts:
75

In DekiScript false as well as nil and zero are logically false, while true and everything else (other than nil, false or 0) are treated as logically true.

  • Was this article helpful?