Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : Create an Auto-Increment Field in LimeSurvey

Create an Auto-Increment Field in LimeSurvey il y a 1 an 11 mois #87032

  • LSCitizen
  • Portrait de LSCitizen
  • Hors ligne
  • Junior Lime
  • Messages : 38
  • Remerciements reçus 1
  • Karma: 1
Hello -

I'm creating a form that tracks events. The ID# will begin with a previous ID# (i.e.: 2012123) so the next ID# should be 2012124. Is there a way to do this in LimeSurvey?
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Create an Auto-Increment Field in LimeSurvey il y a 1 an 11 mois #87060

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4207
  • Remerciements reçus 791
  • Karma: 360
Every case is given a sequential ID in the data. It can be accessed with the {SAVEDID} placeholder after the first page has been submitted.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Create an Auto-Increment Field in LimeSurvey il y a 1 an 11 mois #87175

  • misterdot
  • Portrait de misterdot
  • Hors ligne
  • Junior Lime
  • Messages : 35
  • Remerciements reçus 1
  • Karma: 0
Is there any way to pad that number? I was looking at str_pad in Expression Manager, but that's not working...I assume b/c the response ID is an integer. In my case, I'm trying to capture the initials, location, and entry number for the person doing data entry. So questions would be:

Q1: what are your initials? MM
Q2: what's your location? New York (NY)
Q3: your entry code for this response is MM-NY005.

...where the sequence would be 001 - 900. All works except the padding. My latest attempt looks like this:

your entry code for this response is {INSERTANS:Q1}-{INSERTANS:Q2.value}{SAVEDID}.
It gives MM-NY5.
Thanks,
Matt
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Create an Auto-Increment Field in LimeSurvey il y a 1 an 11 mois #87219

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4207
  • Remerciements reçus 791
  • Karma: 360
SAVEDID is only available if the survey is activated and at least one page has been submitted.

The following should work if the above is true:
Your entry code for this response is - {Q1.shown}-{Q2.code}-{SAVEDID}
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Dernière édition: il y a 1 an 11 mois par tpartner.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Create an Auto-Increment Field in LimeSurvey il y a 1 an 11 mois #87226

  • misterdot
  • Portrait de misterdot
  • Hors ligne
  • Junior Lime
  • Messages : 35
  • Remerciements reçus 1
  • Karma: 0
Thanks, Tony. That does work, but I was wondering if there was a way to pad it with leading 0s. It gives me MM-NY5 instead of MM-NY005.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Create an Auto-Increment Field in LimeSurvey il y a 1 an 11 mois #87227

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4207
  • Remerciements reçus 791
  • Karma: 360
I don't know whether EM can do that.

You may need to put the SAVEDID in a <span> element and then use JavaScript to pad it.

Or, if you just need to store the value, use JavaScript directly to access the SAVEDID and pad it.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Create an Auto-Increment Field in LimeSurvey il y a 1 an 11 mois #87236

  • misterdot
  • Portrait de misterdot
  • Hors ligne
  • Junior Lime
  • Messages : 35
  • Remerciements reçus 1
  • Karma: 0
Below is what I ended up doing. I'm a javascript novice, so I'm sure there's a more efficient way of doing it, but this works - question type is short free text:
Entry ID:
<script type="text/javascript" charset="utf-8"> 
	$(document).ready(function() { 
 
        function pad(number, length) {
          var str = '' + number;
          while (str.length < length) {
          str = '0' + str;
          }
 
        return str;
        }
 
var resp_id = pad({SAVEDID}, 3);
var upper_init = ('{INSERTANS:44474X131X1973}'.toUpperCase());
var answer1 = (upper_init + "-B" + resp_id);
 
document.getElementById('answer44474X121X1977').value = answer1;
});
 
</script>
The output ends up being XX-BNNN were XX is initials entered in a previous question and NNN is the 0 padded response ID. Javascript pad snippet comes from www.electrictoolbox.com/pad-number-zeroes-javascript/.
Thanks,
Matt
L'administrateur a désactivé l'accès en écriture pour le public.

Aw: Create an Auto-Increment Field in LimeSurvey il y a 1 an 10 mois #88881

  • mfs
  • Portrait de mfs
  • Hors ligne
  • Fresh Lemon
  • Messages : 5
  • Karma: 0
Why not simply use
Your entry code for this response is - {Q1.shown}-{Q2.code}-{sprintf("%03d",SAVEDID)}

or alternatively
Your entry code for this response is - {sprintf("%s-%s-%03d",Q1.shown,Q2.code,SAVEDID)}
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Aw: Create an Auto-Increment Field in LimeSurvey il y a 1 an 10 mois #88886

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5325
  • Remerciements reçus 296
  • Karma: 249
mfs has given some very useful hint. Simply format the string using the above function.

More information: www.php.net/manual/en/function.sprintf.php

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.285 secondes
Donation Image