form_set_answer ()

form_set_answer ()

Function prototype

form_set_answer ( session, form_id, question_id , value{, option_id, event_id, form_close = true})

API VersionAll

Updates the value of a question.The update of a question also triggers the following actions:

  • The FORMULAS and CONDITIONS (of conditioned questions)  of the rest of questions in the FORM are reevaluated
  • If form_close = 'true' and after updating the value there are no more pending questions to complete in the FORM, then it will be closed and all ACTION formulas of the FORM will be executed
  • If the FORM is closed and it was the last opened FORM in the corresponding TASK, then the TASK is also closed

If the function returns Y in <refresh> param, is indication to the client for update the summary page. It depends of the calculated fields or conditional values/questions.

Input

parameters:

  • session: is the session id obtained in the session_init call
  • form_id: is the ID of the form obtained by the URL or by the call form_list()
  • question_id: is the ref of a question in a form. The ID can be obtained by the function form_get_summary()
  • value:doesn’t apply for CHECK, RADIO and COMBO question types. Value to store as answer of the question. Beware of the following special case
    • From API Version 2.7.10, when value = NULL, the previous value is not changed. If you want to reset the question, then you should pass an empty string. In previous API versions, the value NULL was considered the same than an empty string
  • option_id: is a valid number for the slected options in CHECK, RADIO and COMBO question types. If the field is a CHECK (multiple answers possible) the selected options are split by ‘|’.
  • event_id: if the form is a template of an event, the event ID reference is needed. In the result, the new form_id is returned.
  • form_close: (default = true) close the FORM automatically if completed (is the last question and all mandatory questions are answered)

Output

parameters:

  • result: contains an Xml with the following information:
    • form_completed: indicates whether the FORM is complete after saving the answer of the question. If the FORM is complete, it is safe to invoke form_close()
    • action_request: A JSON formatted string that suggests an action to the client (e.g. display a TASK or EVENT). This node will only be included when the FORM is closed as a consequence of the invocation to form_set_answer() and the FORM contains an ACTION FORMULA CLIENT_REQUEST () that generates an action request string. It is a choice of the client whether to consider executing the suggested action or not. Introduced in API Version 2.7.16
    • review: Information to review
      • first_question: a reference to the first editable question of the reviewed FORM: It can be used by the client to display the first question if the user wants to make modifications
      • questions: Contains the same information that would be obtained by calling form_get_summary() on a closed FORM. The purpose of this information is to allow the client to show a summary of the FORM without calling form_get_summary.
        NOTE: This node will only be returned when:
        • The FORM has been completed. See below comments about the behavior in embedded FORMs (FORM ITEMs)
        • The FORM TEMPLATE used to create this FORM has the property 'REVIEW' = true
  • refresh: Y/N. If the value is “Y” then the function form_get_summary must be called
  • next: The next question that needs to be answered. There is a special case when a previous question in the FORM is empty and is also mandatory. In this case that question will be returned as 'next question'
  • next_form: Reference to the FORM where the "next" question is located
  • next_task: Reference to the TASK where the "next" question is located
  • next_strict: The next visible question (no matter if it needs to be answered or not, nor whether is editable or not)
  • next_strict_form: Reference to the FORM where the "next_strict" question is located
  • next_strict_task: Reference to the TASK where the "next_strict" question is located
  • ErrorMsg: any fault in the call, either in the validation of input parameters, errors in the connection to the database or any other error, this parameter returns the error message produced
  • ErrorCode: The error code associated to the message returned in ErrroMsg (only if an error happens)

Request

sample:

form_set_answer ( “LCAAAAAAAA”, 1234, 76665, “No”);

Response

sample:

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <?xml version="1.0" encoding="utf-8"?>
  <review_info>
    <form_complete>false</form_complete>
    <action_request/>
    <review>
      <first_question>
        <ref>105288Q1</ref>
      </first_question>
      <questions>
        <question>
          <question_id>105288Q1</question_id>
          <order>100000</order>
          <description_onedit>Question title</description_onedit>
          <num_dec/>
          <mandatory>N</mandatory>
          <exclusive>N</exclusive>
          <tabulation>0</tabulation>
          <description>Question title</description>
          <data_code/>
          <type>STATIC_TEXT</type>
          <is_section_title>true</is_section_title>
          <value/>
          <hidden>false</hidden>
          <literal_format/>
          <value_format/>
          <arrangement/>
          <editable>false</editable>
        </question>
        <question>
          <question_id>105288Q2</question_id>
          <order>200000</order>
          <description_onedit>Simple text</description_onedit>
          <num_dec/>
          <mandatory>N</mandatory>
          <exclusive>N</exclusive>
          <tabulation>0</tabulation>
          <description>Simple text</description>
          <data_code/>
          <type>TEXT</type>
          <value>hola</value>
          <hidden>false</hidden>
          <literal_format/>
          <value_format/>
          <arrangement/>
          <editable>false</editable>
        </question>
        <question>
          <question_id>105288Q3</question_id>
          <order>300000</order>
          <min_value/>
          <max_value/>
          <description_onedit>Numeric question</description_onedit>
          <num_dec/>
          <mandatory>N</mandatory>
          <exclusive>N</exclusive>
          <tabulation>0</tabulation>
          <description>Numeric question</description>
          <data_code/>
          <type>NUMERICAL</type>
          <value>34</value>
          <hidden>false</hidden>
          <literal_format/>
          <value_format/>
          <arrangement/>
          <editable>false</editable>
        </question>
      </questions>
    </review>
  </review_info>
</result>
<refresh>N</refresh>
<!-- CALL form_get_summary () TO REFRESH QUESTION LIST -->
<next>{form_id/}12</next>
<!-- NEXT QUESTION THAT NEEDS TO BE ANSWERED -->
<next_form>52343</next_form>
<!-- FORM OF THE NEXT QUESTION -->
<next_task>63425</next_task>
<!-- TASK OF THE NEXT QUESTION -->
<next_strict>{form_id/}11</next_strict>
<!-- NEXT QUESTION NO MATTER IF IT NEEDS TO BE ANSWERED OR NOT -->
<next_strict_form>52343</next_strict_form>
<!-- FORM OF THE NEXT STRICT QUESTION -->
<next_strict_task>63425</next_strict_task>
<!-- TASK OF THE NEXT STRICT QUESTION -->
<ErrorMsg></ErrorMsg>

Notes:

 In case of error, the Response will be different, only return a empty result and the Error:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<result></result>
<ErrorMsg>ERROR: Parámetros pasados están vacíos</ErrorMsg>