Skip to main content

Multi Table Output in Stored Procedure

To utilize the Multi Table output capability in a stored procedure within OwlGen for comprehensive data retrieval, including associated topics and options, follow the steps mentioned below.

Configure the Stored Procedure​

  1. Create a Stored Procedure: Navigate to the stored procedures section in OwlGen and create a Stored Procedure by providing inputs for the properties, as applicable.
  2. Write SQL Query: Within the property panel, write SQL queries to retrieve data from the relevant database tables by clicking on Open Editor. This includes selecting data from the Topics, Questions, and Options tables using appropriate SQL commands.
  3. Configure Output Type: Set the output type of the stored procedure to "Multi Table" and click on +Add Table to configure the table.

Stored procedure configuration step 1

Stored procedure configuration step 2

Stored procedure configuration step 3

Implement Server Flow Logic​

The queries configured in the Stored Procedure are executed within a server flow named "GetQuestionDetails," which is designed to handle asynchronous operations and expose the procedure as an API endpoint. Within the server flow, a series of logic constructs are employed to process the query results and structure the final response:

  1. Run Query: The "Run Query (Stored Procedure)" construct initiates the execution of the "GetQuestionDetails" stored procedure, facilitating the retrieval of data from multiple tables in the database.

    Within the stored procedure, multiple output parameters are defined to capture data from distinct tables, such as Topics, Questions, and Options.

    PropertyDescriptionExample
    LabelIdentifies the constructRun Query
    TypeSpecifies the construct typeStored Procedure
    QueryNameName of the stored procedure to be executedGetQuestionDetails
    Timeout (secs)Duration before query times out0
    DataSet NameName of the dataset holding query resultsquestionDetailsResponse
    Output Parameters
    TopicsOutput parameter for topicstopics
    Query OutputData output for topicstopics
    Query Output ItemPlaceholder for each topiccurrentTopic
    Data Rows AliasAlias for topic data rowsTopicsRows
    Data Row Item AliasAlias for current topic rowTopicsCurrentRowsItem
    Output MappingMapping of topic attributescurrentTopic.Id, currentTopic.Code, currentTopic.DisplayName
    QuestionsOutput parameter for questionsquestions
    Query OutputData output for questionsquestions
    Query Output ItemPlaceholder for each questioncurrentQuestion
    Data Rows AliasAlias for question data rowsQuestionsRows
    Data Row Item AliasAlias for current question rowQuestionsCurrentRowsItem
    Output MappingMapping of question attributescurrentQuestion.Id, currentQuestion.Code, currentQuestion.QuestionText, currentQuestion.Answer, currentQuestion.TopicId
    OptionsOutput parameter for optionsoptions
    Query Output ItemPlaceholder for each optioncurrentOption
    Data Rows AliasAlias for option data rowsOptionsRows
    Data Row Item AliasAlias for current option rowOptionsCurrentRowsItem
    Output MappingMapping of option attributescurrentOption.Id, currentOption.Code, currentOption.Text, currentOption.QuestionId
  2. Iterate Over Questions: The "ForEach" construct systematically iterates over each retrieved question, enabling individual processing of their details.

    The "Assignment" construct initializes and assigns values to the "selectedQuestion" placeholder, housing vital attributes of each question such as ID, code, question text, and topic ID.

  3. Filter Options: The "Call Aggregate Function" construct filters the options associated with each question based on the question's ID, ensuring that only relevant options are included in the final response.

Server flow logic step 1

Server flow logic step 2

Server flow logic step 3

Server flow logic step 4

Execute and Validate​

  1. Execute Server Flow: Execute the server flow to trigger the retrieval and processing of question details.
  2. Validate API Response: Test the API endpoint associated with the server flow to ensure that it returns the expected question details in a structured and organized format.

By following these steps, you can efficiently utilize the Multi-Table output feature in a stored procedure to retrieve, process, and structure comprehensive question details from multiple database tables in OwlGen.