Question T12717
Visible to All Users

Set dropdown default value from choice

created 2 years ago
JSON
{ name: 'Competitor Material Information', elements: [ { type: 'panel', name: 'coating_info', elements: [ { type: 'dropdown', name: 'competitor_name', title: 'Insulation Coating', choicesByUrl: { url: 'https://scaffold-dev.deliverain.io:8190/Enquiry/FpCoatCode', valueName: 'sinsCoatingType', }, }, { type: 'dropdown', name: 'competitor_specs', title: 'Average coating thickness', startWithNewLine: false, choicesByUrl: { url: 'https://scaffold-dev.deliverain.io:8190/Enquiry/AvgCoatingThickness/{competitor_name}', valueName: 'avgCoatingThickness', }, }, { type: 'dropdown', name: 'competitor_mill', title: 'Min Avg. Insulation Resistivity', choicesByUrl: { url:'https://scaffold-dev.deliverain.io:8190/Enquiry/MinAvgInsulation/{competitor_name}/{competitor_specs}', valueName: 'sirOhmCm2PerLaMin', }, }, { type: 'dropdown', name: 'coating_weldable', startWithNewLine: false, title: 'Weldable', choices: ['Yes', 'No'], }, { type: 'comment', name: 'remarks', title: 'Remarks', hideNumber: true, defaultValue: '1)Coating colour deviation may be possible without affecting the coating properties\n2) Magnetic properties are guaranteed in as received condition and measurement as per IS649.\n3) Average coating thickness is average of both top and bottom.', }, ], title: 'Coating Information', showQuestionNumbers: 'off', }, ], description: 'Coating Information', };

Above is my SurveyJson.As you see the API are interlinked with other dropdown values.
So here I need "competitor_mill" first value to be set from choice which comes from API.
Also if I select one dropdown value from "competitor_name" then the "coating_weldable" value should be set as YES.

NOTE: The dropdown values can be changes anytime so the values should be set accordingly

Answers approved by surveyjs Support

created 2 years ago

Hello Abhishek,

So here I need "competitor_mill" first value to be set from choice which comes from API.

You correctly configured these dropdown questions and included the competitor_name into the choicesByUrl settings of your competitor_mill question (as shown in the Load Data from Web Services demo). Would you please elaborate on your question? Do you wish to disable the competitor_mill question until a user selected a value for the competitor_name question? If so, you can configure the enableIf setting for your competitor_mill question and enable the question only if a master question has a value.

Also if I select one dropdown value from "competitor_name" then the "coating_weldable" value should be set as YES.

For this, please configure the Set Value trigger. For more details, refer to:

I hope this information helps. Please let me know if you have any questions.

    Show previous comments (3)

      Hello Abhishek,
      The options.choices is a list of items. When you work with a list of items, you need to address an item by index. Therefore, you need to modify your code and update the first item as follows: let firstItem = options.choices[0].
      Please try the following code:

      JavaScript
      survey.onLoadChoicesFromServer.add((sender, options) => { if(options.question.name === 'competitor_mill') { options.question.value = options.choices[0]; } })

      I look forward to your reply.

        Hi Jane,

        Is it possible to call a function or something to get the value calculated and get from API??
        There is one text box which depends on one dropdown and other text box.
        textbox -> thktol
        dropdown -> grade
        textbox -> width

        so thktol value should be calculated on basis of grade and width for which i need to call one api after that.
        is it possible?

          Hello,

          I created a separate ticket on your behalf: T12722: Call a function to fetch data from API when other field values are updated. We placed it in our processing queue and will process it shortly.