How to get index / order while mapping an Entity to LocalStorage?
Question
Application Type
Mobile
Service Studio Version
11.53.8 (Build 60995)

Goal

User is entering a survey of 10 randomised questions (out of possible 20 questions) and only showing one question at a time before moving on

Approach

  • Client calls server for randomised list to be returned and sync'd to local storage
  • User navigates to first question, by fetching from local storage the first item using a local variable of Position = 0
  • When user selects their answer, Position is incremented, then screen is updated with the next question to answer from local storage
  • Only on the final question do they submit and the local storage questions & answers are saved back to the server

Issue

I can't seem to find an expression to set Order as an autoincrementing value during the mapping from Server to Local Storage


I want to include the Order (basically 0->9) for each question being returned for two reasons

  • As highlighted above, use the Aggregate filter of Order = Position to show my next item, and just increment Position by one
  • When I browser history, I can use the Order to sort the list


Note: I tried Pagination but that's only for database entities. Carousel and Wizard didn't seem to suit dynamic content / overly complex for what I'm looking to achieve

Ok,

I'm not following the 'without saving to database' part, really, but let's say you don't want to save a lot of begun but unfinished surveys on server side, so you want to wait to save anything on server side until they finish answering, fair enough, allthough a smart test taker will just reload his set of questions until he gets easy ones, and as you don't store any of this on server, how will you detect this, you will need other ways to mitigate this.

At least save the sequence number on the local database.  So you have a server action returning a list of 10 random to be answered questions.  This list has a certain order (either randomized by you in the server logic or not).  You can save that order as a sequence number of the questions in the local database.

As for pagination, you'll have to brew your own if you are working off a local database, make a local variable for current sequencenumber in your screen, defaulted to 1 (or more fancy, you store the sequence number they are on while taking the survey, so if they reopen after closing, they start at the question they were), make an aggregate where you filter on that sequence number.  Now you add paging buttons or something, and in the client event, you just up or down the local variable by 1 and refresh the aggregate (possibly after storing the answer of the question they were on.

See attached oml for a quick demo, you would have to make it fancier, by disabling the < at beginning of set, and the > at end of set, and stuff like that.

And then add another server action "SubmitAnswers" or something.

Dorine


QDR_LocalQuiz.oml

Hi Dorine,


That's what I was looking for, thank you.

I was unaware there was .CurrentRowNumber available to me


I agree with your questions regarding someone continually refreshing, however I've confirmed the behaviour with my manager & customer.


Thank you again

Hi Andrew,

where exactly do you have a problem ?  

As I understand, you have some server action selecting 10 random questions, in random sequence (?) that should serve as the survey questions for a given survey.

I think you might be confusing 2 concepts : 

first of all, you want to make a selection of 10 questions that should make up a single survey to be taken by a given user.  I think you should model that on your server side, regardless of any synchronisation with a local database.  

So you'd have a survey entity, and a surveyQandA entity, with a reference to the survey it is part of, and a reference to the question, and space to store the user's answer to the question.  This entity should have a sequence number attribute, and your server action doing the random selection out of the whole batch of available questions, should assign each selected question a sequence number.

A completely different subject is, if and how much of this do you want to sync to a local database on the device.  I think you could do something like have one local entity with only the 10 records for the current survey, holding question details, answer details and sequence number.  

Regardless of whether you use a local synced database or not, your UI can just use pagination with a page size of 1 to go through the questions, and the aggregate retrieving these questions should sort on the sequence number.

Dorine

Hi Dorine,


Thank you for the quick reply.


The main issue is I want to set an autoincrementing value to a list of objects without saving it to the database but can't work it out. I don't mind if it's server or client side.

Is that possible?


----

> A completely different subject is, if and how much of this do you want to sync to a local database on the device. 

Very little. I basically wanted a single server action to return a list of randomised questions (not saved in DB), then client to store them in local storage. Then at submission, push it back to server / store in the database.

----

> your UI can just use pagination with a page size of 1 to go through the questions 

This doesn't work for local storage as the aggregate list doesn't have a "Start Index" option, only the database aggregate does

I was following this documentation

https://success.outsystems.com/Documentation/11/Developing_an_Application/Design_UI/Patterns/Using_Mobile_and_Reactive_Patterns/Navigation/Pagination

If there's a work around, that would be helpful. It seems other forum posts recommended Carousel / Wizard

Ok,

I'm not following the 'without saving to database' part, really, but let's say you don't want to save a lot of begun but unfinished surveys on server side, so you want to wait to save anything on server side until they finish answering, fair enough, allthough a smart test taker will just reload his set of questions until he gets easy ones, and as you don't store any of this on server, how will you detect this, you will need other ways to mitigate this.

At least save the sequence number on the local database.  So you have a server action returning a list of 10 random to be answered questions.  This list has a certain order (either randomized by you in the server logic or not).  You can save that order as a sequence number of the questions in the local database.

As for pagination, you'll have to brew your own if you are working off a local database, make a local variable for current sequencenumber in your screen, defaulted to 1 (or more fancy, you store the sequence number they are on while taking the survey, so if they reopen after closing, they start at the question they were), make an aggregate where you filter on that sequence number.  Now you add paging buttons or something, and in the client event, you just up or down the local variable by 1 and refresh the aggregate (possibly after storing the answer of the question they were on.

See attached oml for a quick demo, you would have to make it fancier, by disabling the < at beginning of set, and the > at end of set, and stuff like that.

And then add another server action "SubmitAnswers" or something.

Dorine


QDR_LocalQuiz.oml

Hi Dorine,


That's what I was looking for, thank you.

I was unaware there was .CurrentRowNumber available to me


I agree with your questions regarding someone continually refreshing, however I've confirmed the behaviour with my manager & customer.


Thank you again

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.