jdcaliff jdcaliff - 17 days ago 4
Javascript Question

NetSuite Suitelet SSv2 how to populate multiselect with object

I am trying to simply populate a multiselect field with a list of marketplaces.

Here is the marketplaces object:

var marketplaces = {

amazonCom:{
label: 'Amazon.com',
searchId: 'customsearch_ca_export_detail_search__21',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_us'
},

amazonUK:{
label: 'Amazon.uk',
searchId: 'customsearch_ca_export_detail_search__33',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_uk'
},

amazonCA:{
label: 'Amazon.ca',
searchId: 'customsearch_ca_export_detail_search__23',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_ca'
},

amazonFR:{
label: 'Amazon.fr',
searchId: 'customsearch_ca_export_detail_search__26',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_fr'
},

amazonDE:{
label: 'Amazon.de',
searchId: 'customsearch_ca_export_detail_search__24',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_de'
},

amazonIT:{
label: 'Amazon.it',
searchId: 'customsearch_ca_export_detail_search__29',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_it'
},

amazonJP:{
label: 'Amazon.co.jp',
searchId: 'customsearch_ca_export_detail_search__30',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_jp'
},

amazonES:{
label: 'Amazon.es',
searchId: 'customsearch_ca_export_detail_search__37',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_es'
},

ebayCom:{
label: 'eBay.com',
searchId: 'customsearch_ca_export_detail_search__34',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_us2'
},

ebayUk:{
label: 'eBay.uk',
searchId: 'customsearch_ca_export_detail_search__51',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_uk2'
},

ebayAu:{
label: 'Amazon.au',
searchId: 'customsearch_ca_export_detail_search__50',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_au'
},

ebayVolt:{
label: 'eBay.com Volt',
searchId: 'customsearch_ca_export_detail_search__35',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_volt'
}

};


I am trying to follow the documentation to populate the multiselect field. Here is the code:

var marketplacesList = form.addField({

id:'selectedmarketplaces',
type:ui.FieldType.MULTISELECT,
label:'Marketplaces'

});

for (var i = 0; i<marketplaces.length; i++){

marketplacesList.addSelectOption({

value: marketplaces[i].label,
text: marketplaces[i].label

});

}


Any help?

Thanks,


  • Jesse


Answer

Your issue is that marketplaces is not an array, so it does not have a length property.

Try replacing the for line with:

for (var i in marketplaces) {
    if(!marketplaces.hasOwnProperty(i)) {
        continue;
    }

    //  Add option for form or whatever...
}