• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
        • Logic Action Invoker Namespace
        • Logic.eval Action
        • Logic.getSymbol Action
        • Logic.getSymbolMetadata Action
        • Logic.getSymbolValue Action
        • Logic.invoke Action
        • Logic.updateSymbolValue Action
      • Message Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Logic.invoke Action

Format
s = CS.Logic.invoke(function := ...ʃ, arguments := ...ʅ)
ArgumentDescriptionTypes / Required
functionThe name of the user-defined function.string
required
argumentsThe arguments to the user-defined function.object
not required
Description
The Logic.invoke action executes a user-defined function using runtime binding. The function argument specifies the name of the function, and any arguments required by the function can be passed by specifying arguments. Each of the arguments object's names is matched with the name of a function parameter, and the value is bound to that parameter using the rules for representing symbols in JSON.
Because logic functions can display UI elements, it is a good idea to use the asynchronous version of this action when using this action from a web view.
Functions can also be executed at runtime using the Logic.eval action and the invoke function.
Return Value
The action returns the user-defined function's return value as a number or string.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form, or if:
  • No function has the specified name.
  • No argument is provided for a required function parameter.
  • An argument cannot be converted from JSON to its logic version.
Example (HTML + JavaScript)
This example uses the asynchronous version of Logic.invoke to ensure that the UI elements of the List.show function call are displayed correctly.
<script>
    const CS = new CSProActionInvoker();

    CS.Logic.invokeAsync({
        function: "QueryUser",
        arguments: {
            message: "Did you attend any of these universities?",
            options: [
                "Harvard University",
                "University of Virginia"
            ]
        }
    })
    .then(selection => {
        console.log(`Selection was ${selection}.`);
    })
    .catch(e => {
        CS.UI.alertAsync({
            text: e.message
        });
    });
</script>
The logic function that is called by the above JavaScript:
// this function displays a message and presents a list of options from which the user can select
function numeric QueryUser(string message, optional List string options)

   
// add OK as a default option if no options are provided
    if options.length() = 0 then
        options.
add("OK");
   
endif;

   
exit options.show(message);

end;
See also: Logic Action Invoker Namespace, Logic.eval Action, Invoke Function, User-Defined Functions