Search code examples
netsuitesuitescriptsuitescript2.0

currentRecord.setText defualting to last value


I have a custom suitelet which I am trying to set the values of a couple select fields on a client script.

I have a list of sales reps which is generated by a search in the suitlet.

            var salesrep = form.addField({
                id : 'custpage_salesrep',
                label : 'Sales Rep',
                type : serverWidget.FieldType.SELECT,
                container : 'reportcriteria'
            });

            salesrep.addSelectOption({
                value : 0,
                text : '-All-'
            });

             getSalesrepSearch().run().each(function(result){
                salesrep.addSelectOption({
                    value : result,
                    text : result.getValue('firstname') + ' ' + result.getValue('lastname')
                });

                salesrepArray.push([result.getValue('firstname') + ' ' + 
                result.getValue('lastname'),result.id])
                return true
            })

on the client script I am trying to set the text value with the following

            recObj.setText({
                fieldId: 'custpage_salesrep',
                text: dataSalesRep
            });

For some reason no matter what I do the field is set to the last name/ value on the list.

  • I have confirmed that the name is correct (console log shows the correct name)
  • I have hard coded the correct text and received the same result.

This is the only field having an issue and the only difference is that the list is populated from the search. I am not sure if that is affecting the outcome.


Solution

  • After some additional debugging I discovered that by using the result for value, I was actually setting the value to the whole result object. So instead I added a counter and that solved my problem.

            var i = 0
            getSalesrepSearch().run().each(function(result){
                salesrep.addSelectOption({
                    value : i,
                    text : result.getValue('firstname') + ' ' + result.getValue('lastname')
                });
    
                salesrepArray.push([result.getValue('firstname') + ' ' + result.getValue('lastname'),result.id])
                i++
                return true
            })