Set a question's JavaScript from API | XM Community
Solved

Set a question's JavaScript from API

  • 28 September 2020
  • 1 reply
  • 75 views

Badge +5

How do I add JavaScript to a question via an API POST statement?
I can add HTML fine, but I don't know how to set (or get) the JavaScript other than doing it manually for each question. I searched here, StackOverflow, and Google; I found plenty about working with JavaScript manually, but I couldn't locate anything about doing this via the API.
If it helps, below is a sample of my questionDef in Python. Each question ties to an ID, and the JavaScript creates the actual question text based on that ID (e.g., this one is question #486).
questionDef = {
  "Configuration": {
    "QuestionDescriptionOption": "UseText"
  },
  "DataExportTag": "Ques486Stem",
  "DefaultChoices": False,
  "QuestionDescription":"lbl_q486z-stem",
  "QuestionText": '

q486z-stem
',
  "QuestionType": "TE",
  "Selector": "SL"
}
I'm new to the API environment, so I apologize if I'm missing something obvious.

icon

Best answer by BDT 29 September 2020, 08:30

View original

1 reply

Badge +5

Got it! Just include QuestionJS as a key within the question definition. For example, I might modify the code below to include QuestionJS:
QuestionJSquestionDef = {
  "DataExportTag": "Ques486Stem",
...
  "QuestionJS": <>
}

Leave a Reply