LimeSurvey日期格式转换及URL变量与SCSM对接技术问询
Hey there! Let's break down your two LimeSurvey challenges step by step:
The approach depends on where you need the format change to happen:
For survey question input fields
If you want respondents to enter dates in mm/dd/yyyy (or display existing date fields in this format), head straight to the question editor:
- Find the Date format dropdown in the question settings
- Select
mm/dd/yyyydirectly. That’s the simplest fix for new or existing date questions.
For processing incoming date values (like URL parameters)
If you’re pulling dates from external sources (like your SCSM URL) in dd/mm/yyyy and need to convert them to mm/dd/yyyy, use LimeSurvey’s custom scripting or Expression Manager:
- Use the
beforeSurveyStartevent (under Survey settings > Scripts) to add this PHP snippet:
// Replace $createddate with your actual question code/URL parameter if (isset($_GET['createddate'])) { $originalDate = $_GET['createddate']; // Parse dd/mm/yyyy format $dateObj = DateTime::createFromFormat('d/m/Y', $originalDate); if ($dateObj) { // Convert to mm/dd/yyyy and assign to the question field $this->setAnswer('createddate', $dateObj->format('m/d/Y')); } }
- This ensures the date is stored or displayed in your desired format before the survey loads.
For exporting survey data
When exporting responses, look for the Date format option in the export settings menu, then select mm/dd/yyyy to download data in that format.
Your setup (passing parameters like ticket, createddate via URL) is totally doable—here’s how to make it work smoothly:
Step 1: Ensure LimeSurvey accepts URL parameters
- First, create text fields in your survey with exact matching question codes (e.g.,
ticket,createddate,resolveddate,closeddate)—case sensitivity matters here! - Go to Survey settings > Presentation & navigation (or Tokens & security in newer versions) and enable the option to Allow URL parameters to let LimeSurvey pull values from the URL into the corresponding fields.
Step 2: Fix URL formatting (minor tweak)
Your example URL has a ?& which works but isn’t standard. Adjust it to start with a single ? like this:https://poll.company.com/index.php/survey/index/sid/123456/newest/y?ticket=IR123456&createddate=1/31/2018&resolveddate=2/1/2018&closeddate=2/3/2018
LimeSurvey will still parse the original, but this is cleaner.
Step 3: Sync survey responses back to SCSM
If you need to send completed survey data back to SCSM, use LimeSurvey’s afterSurveyComplete script to trigger an API call:
- Add this snippet in Survey settings > Scripts > afterSurveyComplete:
// Collect survey answers $surveyData = [ 'ticket' => $this->getAnswer('ticket'), 'createddate' => $this->getAnswer('createddate'), 'resolveddate' => $this->getAnswer('resolveddate'), 'closeddate' => $this->getAnswer('closeddate'), // Add other response fields as needed ]; // Send data to SCSM API (update the URL and auth headers to match your SCSM setup) $ch = curl_init('https://your-scsm-instance.com/api/endpoint'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($surveyData)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer YOUR_SCSM_API_KEY' // Adjust auth method as needed ]); curl_exec($ch); curl_close($ch);
- Make sure to match SCSM’s API requirements for authentication and data format—you might need to tweak the payload structure to fit their schema.
内容的提问来源于stack exchange,提问作者Aldin Kevric

