Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Create a relation between custom data and survey data.

  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 weeks ago #196009 by AuPath
Hello everyone, i'm a new limesurvey user and was trying to integrate limesurvey with a custom javascript script that tracks the user's mouse movement.
My issue is when i try to associate this custom data with the survey data, specifically a survey record.
When i look into the database i can see that each survey has a series of records with an id, it would be great if i could use this id as a foreign key in my custom data. How can i have access to this id while the user is taking the survey? Is that possible? Does anyone have a better solution?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196017 by holch
Code:
{SAVEDID}

SavedID gives you the ID that Limesurvey is giving to the current response.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 weeks ago #196018 by AuPath
Thank you, another quick question, under what scope do i have access to {SAVEDID} ? What i'm currently doing is making a custom theme where i added a <script> tag in the question page. When i try to for example console.log({SAVEDID}) it does not print the id, it prints {SAVEDID}. Sorry if it's a stupid question but i'm a total beginner.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196021 by holch
You should be able to use {SAVEDID} anywhere in your survey to display it.

I have no ID with Javascript, but I have heard that LS only recognizes EM code in JS code if you leave a space before the code. So you could try this.

I probably would write the {SAVEDID} into a equation type question and hide it via CSS (not via the GUI "Always hide this question", because JS can't access it then).

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 weeks ago #196023 by AuPath
Do you have a link on how to reference questions with JS?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago - 4 years 2 weeks ago #196024 by tpartner

Thank you, another quick question, under what scope do i have access to {SAVEDID} ? What i'm currently doing is making a custom theme where i added a <script> tag in the question page. When i try to for example console.log({SAVEDID}) it does not print the id, it prints {SAVEDID}.

You will need to wrap {SAVEDID} in quotes as it is not a JavaScript variable.

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    console.log('{SAVEDID}');
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 2 weeks ago by tpartner.
The following user(s) said Thank You: holch
The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 weeks ago #196027 by AuPath
Thank you for your reply but this does not seem to work, it just prints {SAVEDID}.
Just to be clear i am putting this code in the question.twig page of my custom theme.
I'm doing this because i want this code to be applied to all questions of all surveys that use this theme.
Is this the wrong approach?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196029 by tpartner
Placeholders are not directly available in TWIG files, you need to define them via the processString() function.

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    console.log('{{ processString('{SAVEDID}') }}');
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose