I am trying to create some code that updates a sto...
# suitescript
k
I am trying to create some code that updates a stored value field based upon a custom school record to a customer record. I imported the search module to search through all customer records and if the school name matches the school list field then update the customer record to match the school record. The code I have is not working. It originally worked before I added the functionality to compare the school name to the school list. Any suggestions on how to get this to work?
Copy code
const beforeSubmit = (scriptContext) => {

    var newRecord = scriptContext.newRecord
    var oldRecord =scriptContext.oldRecord


    var standardRoyalty = newRecord.getValue({
        fieldId: 'custrecord_lf_school_std_roy_perc'
    });
    var headwearRoyalty = newRecord.getValue({
        fieldId: 'custrecord_lf_school_hdwr_roy_perc'
    })
    var schoolName = newRecord.getValue({
        fieldId: 'custrecord_lf_school_name'
    })

    var mysearch = search.create({
        type: search.Type.CUSTOMER,
        columns: ['entityid', 'companyname', 'custentity_lf_school_list']
    });

    var myResultSet = mysearch.run();

    for(var i=0; i < myResultSet.length; i++){
        if(  schoolName === myResultSet[i].values.custentity_lf_school_list[0].text){
            var CustomerId = myResultSet[i].id;
            var id = record.submitFields({
                type: record.Type.CUSTOMER,
                id:CustomerId,
                values: {
                    'custentity_lf_hdwr_roy_new': headwearRoyalty,
                    'custentity_lf_std_roy_rate_new' : standardRoyalty
                }
            })
        }
    }
}
e
log
schoolName
and
myResultSet[i].values.custentity_lf_school_list[0].text
. One may be a number
k
@ehcanadian Yes, schoolName returns a number. Any idea on how to get the string value of the school name?
e
getText
instead of
getValue