• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
      • Procedural Sections
      • Logic
        • View Logic
        • Create and Edit Logic
        • Find and Replace Logic
        • Compile Logic / An Application
        • OnKey Character Map
        • OnViewQuestionnaire Global Function
        • User and Configuration Settings
        • String Encoder Dialog
        • Path Adjuster Dialog
        • Symbol Analysis
      • Language Elements
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

OnViewQuestionnaire Global Function

Format
function numeric OnViewQuestionnaire(ʃstring dictionary_nameʅ)
Description
OnViewQuestionnaire is a special global function. It is called during a data entry application when a user attempts to open the questionnaire view from the menu (View > Questionnaire). This function allows you to disable the viewing of questionnaires, or display the questionnaire using a custom action. As with other user-defined functions, it must be defined in the PROC GLOBAL section.
The function can be defined without parameters, or with a single string parameter. If one string parameter is provided, then it will receive the name of the dictionary that forms the basis of the questionnaire.
Return Value
Return 0, or a special value, to prevent the default behavior of viewing the questionnaire. Returning any other value means that the questionnaire will be viewed.
Example 1
In this example, the function prevents non-supervisors from opening the questionnaire view for the staff dictionary.
PROC GLOBAL

function numeric OnViewQuestionnaire(string dictionary_name)

   
// only allow supervisors to view cases from the STAFF_DICT dictionary
    if dictionary_name = "STAFF_DICT" and STAFF_ROLE <> "SUPERVISOR" then
       
errmsg("Staff with role '%s' are unable to view the '%s' questionnaire.", STAFF_ROLE, dictionary_name);
       
exit 0;
   
endif;

   
// allow the viewing of the questionnaire
    exit 1;

end;
Example 2
In this example, the input to view the main dictionary is constructed without the question text, overriding the default behavior that would show this information.
function numeric OnViewQuestionnaire(string dictionary_name)

   
// construct the input needed for the questionnaire view
    string questionnaireViewInput =
       
maketext("{ \"dictionary\": %s, \"forms\": %s, \"case\": %s }",
                 
CS.Dictionary.getDictionary(name := dictionary_name),
                 
CS.Application.getFormFile(name := dictionary_name),
                 
CS.Data.getCase(name := dictionary_name));

   
// pass this input to the questionnaire view
    CS.UI.view(path := Path.concat(html, "questionnaire-view", "index.html"),
               
inputData := @object questionnaireViewInput);

   
exit 0;

end;
See also: Questionnaire View