Hi Jon,
Thanks for your response, and for the link to the example of skip logic in the documentation. I'll take another look at it.
Regarding my question on concatenating values in a survey to fill the primary key field, here is some more information:
I need to be able to locate and identify records after they have been entered using a survey, but the Surveys webpart will only display a single field containing identifying information from a record - either the Label field or, if you customize it, the user-defined primary key.
The date I am entering is uniquely identified through a combination of three pieces of data - the Patient ID, the Visit, and the Sample.
I therefore need to concatenate these three pieces of data into a single field to display it - and that field must be either the Label or the user-defined Primary Key.
So for example if the Patient was number 1, the visit was day 3 and the sample taken was blood, the data would be: PatientID = 01, Visit = D3 and Sample = PB, and the user will enter these three values in a survey form. The desired value for the field displayed (either the Label or the user-defined PK) would therefore be 01_D3_PB.
My question: is it possible to write the Survey form in such a manner as to automatically populate a field with this concatenated string once the user has entered these three values?
Hope this helps,
Simon |
Hi Simon,
It took a bit, but I think I created a pretty solid way to give you what you're looking for.
So the code does a few things:
1. It removes the actual Survey Label and hides it. If you use "useDefaultLabel", it hides the survey label and uses a date and timestamp on the table where it stores the survey information.
2. This survey has two sections:
- One for the User ID that combines all three values from patient, visit, and sample fields into one concatenated value
- One for the three values of Patient ID, Value ID, and Sample IDs.
3. The User ID field has a listener attached that listens for all three fields in the lower section and then populates the value in the User ID box separated with underscores.
For example, a Patient ID of "123ABC", a Visit ID of "02012016-1330", and a Sample ID of "Samp9999" would become "123ABC_02012016-1330_Samp9999" in the User ID field.
4. The User ID field has been purposely configured to ignore anything put in that box and will also disable itself so you can't change it without changing the three other fields.
It took a bit to figure out how to write out the function within the listener, since I had to find a way to have the listener specifically target only those three fields and then concatenating the values and then setting the value of the User ID field accordingly.
Take a look at the code below and give it a try. I think this should do the trick.
Regards,
Jon
{
"survey" : {
"layout" : "auto",
"start" : {
"useDefaultLabel": true
},
"showCounts" : false,
"sections" : [{
"questions" : [{
"name" : "user",
"caption" : "User Id",
"shortCaption" : "User Id",
"hidden" : false,
"jsonType" : "string",
"inputType" : "text",
"required" : false,
"width" : 800,
"setDisabled": true,
"listeners" : {
"change" : {
"question" : ["patient","visit","sample"],
"fn" : "function(me, cmp, newValue, oldValue){var pid = cmp.getName(); vid = cmp.getName(); sid = cmp.getName(); if (pid == 'patient') {pidVal = newValue;} else if (vid == 'visit') {vidVal = newValue;} else if (sid == 'sample') {sidVal = newValue;} else {return true;} me.setValue(pidVal + '_' + vidVal + '_' + sidVal); me.setDisabled(true);} "
}
}
}],
"description" : null,
"header" : true,
"title" : "User Information",
"collapsible" : false,
"defaultLabelWidth" : 350
},{
"questions" : [{
"name" : "patient",
"caption" : "Patient Id",
"shortCaption" : "Patient Id",
"hidden" : false,
"jsonType" : "string",
"inputType" : "text",
"required" : true,
"width" : 800
},{
"name" : "visit",
"caption" : "Visit Id",
"shortCaption" : "Visit Id",
"hidden" : false,
"jsonType" : "string",
"inputType" : "text",
"required" : true,
"width" : 800
}, {
"name" : "sample",
"caption" : "Sample Id",
"shortCaption" : "Sample Id",
"hidden" : false,
"jsonType" : "string",
"inputType" : "text",
"required" : true,
"width" : 800
}],
"description" : null,
"header" : true,
"title" : "Medical Form",
"collapsible" : true,
"defaultLabelWidth" : 350
} ]
}
} |