Let's take a look at how we can pull apart and capture specific Meta Data.
The following example demonstrates accessing and parsing the meta data of a chosen Australian
post code. The post code value and suburb name will be pulled out separately from the Meta Data and
set into other questions on the page. To access the questions with scripting, ensure each question
as a unique Question Access Code.
First create the survey structure:
Retrieving the Text List meta data with script is very easy once the data has been parsed using the
JSON.parse() Javascript method:
You can then simply access and set the data you need from the parsed object:
///Get the survey page questions
var oQTextList = wscScripting.getQuestionByDataPipingCode('AUSPOSTCODES');
var oQSuburb_Name = wscScripting.getQuestionByDataPipingCode('SUBURB_NAME');
var oQPostcode = wscScripting.getQuestionByDataPipingCode('POSTCODE');
///Get the text list metadata using the question identity
var oMetaData = $('#' + oQTextList.identity + '_metadata').val();
///Parse the text list meta data
var oParsedMetaData = JSON.parse(oMetaData);
///Get the postcode from the metadata, convert the value from a string data type to an integer
var nPostCode = parseFloat(oParsedMetaData.PostalCode);
///Set the postcode integer into the numeric question
wscScripting.setValue(oQPostcode, nPostCode);
///Set the suburb name into the single line text question
wscScripting.setValue(oQSuburb_Name, oParsedMetaData.Suburb);
The script above will set the numeric post code and suburb text into the two additional questions when the
next/submit button is clicked: