• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • CSPro Program Structure
      • Programming Standards
      • Change Code Properties
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
      • Procedural Sections
      • Logic
      • Language Elements
      • JavaScript Use in CSPro
        • Overview
        • JS Namespace
        • JS.eval Function
        • JS.invoke Function
        • JS.getValue Function
        • JS.getValueJson Function
        • JS.hasValue Function
        • JS.setValue Function
        • JS.setValueFromJson Function
        • JavaScript User-Defined Functions
        • CSPro ⇄ JavaScript Value Conversions
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

CSPro ⇄ JavaScript Value Conversions

Some CSPro symbols have routines that support the conversion of values from CSPro to and from JavaScript objects. These operations occur explicitly when using functions such as JS.getValue and JS.setValue, and occur implicitly when using JS.invoke or calling a JavaScript user-defined function.
Only some CSPro types have conversion routines. The following table summarizes conversion routines, with the conversion described in detail at the provided links:
CSPro ObjectJavaScript Conversion
numericConverted to a JavaScript number (or null or string if a special value).
Converted from these types, as well as from booleans and single-value arrays.
 
string / alphaConverted to a JavaScript string.
Converted from a string, number, boolean, or null.
 
functionConverted to a JavaScript function.
It is not possible to convert a JavaScript function to a CSPro function.
 
ArrayConverted to and from a JavaScript array.
 
HashMapConverted to and from a JavaScript object.
 
ListConverted to and from a JavaScript array.
Example
// displays: JavaScript print: CSPro values converted to JavaScript: 1.23 null MISSING
JS.invoke("print", "CSPro values converted to JavaScript:", 1.23, notappl, missing);

// displays: JavaScript print: CSPro objects converted to JavaScript: 1,4,9,16 43,days
Array numeric cspro_numeric_array(2, 2) = 1, 4, 9, 16;
List string cspro_string_list = "43", "days";

JS.invoke("print", "CSPro objects converted to JavaScript:", cspro_numeric_array, cspro_string_list);

// displays: Independence Hall is located in Philadelphia (39.95, -75.15)
JS.eval("var js_location_independence_hall = { \"latitude\": 39.95, \"longitude\": -75.15 };");

HashMap string cspro_location_independence_hall;
JS.getValue("js_location_independence_hall", cspro_location_independence_hall);

errmsg("Independence Hall is located in Philadelphia (%v, %v)",
       cspro_location_independence_hall(
"latitude"),
       cspro_location_independence_hall(
"longitude"));
See also: JavaScript Use in CSPro, JS.getValue Function, JS.setValue Function