show / hide menu

Execute & Invoke JavaScript Functions

ExecuteJavaScript ():
This function is available in the ClaySys AppForms which enables the user to execute the JavaScript code written within the braces.
1. SYNTAX:

  •   Argument:

➣  JavaScript Code: The JavaScript code.

2. Example to implement the function ExecuteJavaScript() without returning any value.

  • Create a form in ClaySys AppForms with a button as shown below where the function ExecuteJavaScript() has to be executed on a button click.
  • Create a new rule from the ‘Rules Panel’ with the button as a trigger.

  ➣ Add an action to the newly created rule by clicking on button .

➣Now an ’Expression Builder ‘ gets open up.

  • Select the group ‘Functions’ from the first section.
  • Select the group as ‘Script Operations’ from the listed group of functions.
  • Select the script operation as ‘ExecuteJavaScript’ from the listed script functions and click on button .

  • The selected function gets added up to the ‘Selected Expression’ field
  • Now the JavaScriptCode for execution has to be manually added as the parameter for the function which is mandatory .The JavaScriptCode added as the parameter should be enclosed within double quotes.
  • Now click on button ‘Verify’ to verify the selected expression .
  • The selected expression gets added as a new action for the rule upon clicking on button ‘Done’.
  • In Preview ,

➣ The executed result of the JavaScriptCode will be shown in the preview on the button click.

3.Example to implement the function ExecuteJavaScript() that returns a value.

  • Create a form in ClaySys AppForms with a button as shown below where the function ExecuteJavaScript() has to be executed on a button click.
  • Create a new rule from the ‘Rules Panel’ with the ‘FormLoad’ as a trigger.

➣ Add an action to the newly created rule by clicking on button ..

➣Now an ’Expression Builder ‘ gets open up.

  • Select the group ‘Functions’ from the first section.
  • Select the group as ‘Script Operations’ from the listed group of functions.
  • Select the script operation as ‘ExecuteJavaScript’ from the listed script functions and click on button .
  • The selected function gets added up to the ‘Selected Expression’ field.
  • Now the JavaScriptCode containing a return value has to be manually added as the parameter for the function which is mandatory. The JavaScriptCode added as the parameter should be enclosed within double quotes.
  • Assign the selected expression to a variable.

✤ A pop up to create a variable gets open up by clicking on the button ‘Manage Variables’.

✤ Name the variable and click on button ‘Save Variable’ to save the newly created variable.

✤ Now assign the result of the execution of function ExecuteJavaScript() to the variable created.

  • Now click on button ‘Verify’ to verify the selected expression .
  • The selected expression gets added as a new action for the rule upon clicking on button ‘Done’.

➣Now add another rule to pop up the value of the variable containing the execution result as a message on the button click.

  • In Preview ,
  • ➣The executed result of the JavaScriptCode which is assigned to the variable will be shown in the preview on the button click.

    4. The above sessions can also be done as shown below:
    User can execute the JavaScriptCode dynamically from the preview.

    • Create a form in ClaySys AppForms as shown below.

    ➣ Create a rule such that the JavaScriptCode gets executed in the button trigger as explained in the above sessions.

    • In Preview,

    ➣ Enter the data into the textbox named ‘fname’ in the designer.
    ➣ Now enter the JavaScriptCode that has to be executed on the button click.
    ➣ On button click, the JavaScriptCode gets executed and the result gets displayed.
    The script example below will read the value typed in the textbox fname and display a alert message using javascript.
    var x = document.getElementsByNames(“fname”)[0].value;
    alert(x);

    InvokeJavaScript ():
    This function is available in the ClaySys AppForms which enables the user to execute the JavaScript functions available in the ClaySys AppForms.

    1.SYNTAX:

    • Arguments:

    ➣ ScriptFunctionName: Name of the JavaScript function.
    ➣ Parameters: This is optional. The Parameters to the JavaScript function can be ‘n’ numbers separated by a comma.

    5.Example to implement the function InvokeJavaScript() without a parameter.

    • Create a form in ClaySys AppForms with a button as shown below where the function InvokeJavaScript() has to be executed on a button click.
    • Create a new rule from the ‘Rules Panel’ with the button as a trigger.

    ➣ Add an action to the newly created rule by clicking on button.

    ➣ Now an’ Expression Builder ‘ gets open up.

    • Select the group ‘Functions’ from the first section.
    • select the group as ‘Script Operations’ from the listed group of functions.
    • Select the script operation as ‘InvokeJavaScript’ from the listed script functions and click on button.
    • The selected function gets added up to the ‘Selected Expression’ field.

    • Now the name of the JavaScript function has to be mention within braces which is mandatory.

    ✤ Here the function Resolution() is defined as below:
             function Resolution()
             {
                   var width = window.screen.width;
                   alert(width);
             }

    • Now click on button ‘Verify’ to verify the selected expression .
    • The selected expression gets added as a new action for the rule upon clicking on button ‘Done’.
    • In Preview ,

    ➣ The executed result of the JavaScript Function will be shown in the preview on the button click.

    6. Example to implement the function Invoke JavaScript() with parameters.

    • Create a form in ClaySys AppForms with a button as shown below where the function InvokeJavaScript() has to be executed on a button click.
    • Create a new rule from the ‘Rules Panel’ with the button as a trigger.

    ➣Add an action to the newly created rule by clicking on button.

    ➣ Now an’ Expression Builder ‘ gets open up.

    • Select the group ‘Functions’ from the first section.
    • select the group as ‘Script Operations’ from the listed group of functions.
    • Select the script operation as ‘InvokeJavaScript’ from the listed script functions and click on button.
  • The selected function gets added up to the ‘Selected Expression’ field.
    • Now the name of the JavaScript function has to be mention as the first parameter which is mandatory.

    ✤ Here the function foo() is defined as below:
    function foo(value)
    {
    alert(value);
    }

    • The values that has to be passed to the JavaScript function needs to be entered as the parameters in the function ‘InvokeJavaScript()’ separated with a comma. This is optional.
    • Now click on button ‘Verify’ to verify the selected expression .
    • The selected expression gets added as a new action for the rule upon clicking on button ‘Done’.
    • In Preview,

    ➣ The executed result of the JavaScript Function will be shown in the preview on the button click.