Error handling using e.stack

In JavaScript, including SuiteScript 2.0, the Error object includes a stack property that provides a string representation of the point in the code at which the Error was instantiated. This can be particularly useful for debugging.

Below is the reference code

            try
            {
                let result = JSON.parse(mapContext.value)
                let entity = result.values.entity.value;
                let tranid = result.values.entity.value;
                let total  = result.values.total.value;
                let overdue = result.values.daysoverdue.value;
                let lookupsearchObj = search.lookupFields({
                    type: search.Type.CUSTOMER,
                    id: entity,
                    columns: ['entityid','email']
                 });
                 let entityname = lookupsearchObj.getText('entityid');
                 let entityemail = lookupsearchObj.getValue('email');


                 details ={
                    customer : entityname,
                    customerId: entity,
                    customerEmail:entityemail,
                    invoicedocno : tranid,
                    invoicetotal : total,
                    overdue : overdue,


                 }
                 return mapContext.write({
                    key:entity,
                    value:details
                 })
            }catch(e){
                log.error("error details",e.message,e.stack);
     


This will give you the code with line where the error occured .

Leave a comment

Your email address will not be published. Required fields are marked *