Entry Point Question I have a beforeSubmit User E...
# suitescript
m
Entry Point Question I have a beforeSubmit User Event Script running on support case records. I am creating and updating these records via Suitelet script (Celigo integration). My script is firing when the record is created but not updated. Is context.newRecord not passed when editing via Suitelet? I am getting missing search operator errors.
b
newRecord is basically always there
basic troubleshooting for user events not triggering is making sure that the script deployment's audience is set correctly
and that the event type and context filtering is setup correctly
m
I should probably rephrase a bit. In my script I am creating a search with a filter of the ‘company’ on the support case record. When the support cases are edited, the following error is thrown: SSS_INVALID_SRCH_OPERATOR When editing in the UI, the script works fine.
b
share the code and the message
assuming you have the deployment setup correctly, my guess is that your script doesnt support xedit
m
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */

define(['N/search', 'N/record'],

function (search, record) {


function beforeSubmit (context) {

   try {
    var currIncident = context.newRecord;
    var oldIncident = context.oldRecord;
    var currCustomer = currIncident.getValue({
        fieldId : 'company'
    });


    var mySNAR_Search = search.create({
        type: "customer",
        filters: [ 
            ["internalid","anyof",currCustomer]
                ],
        columns:
        [
           search.createColumn({
              name: "name",
              join: "CUSTRECORD_CUSTOMER_UNIT",
              label: "Name",
              sort: search.Sort.NONE
           }),
           search.createColumn({
              name: "custrecord_unit_status",
              join: "CUSTRECORD_CUSTOMER_UNIT",
              label: "Unit Status",
              sort: search.Sort.ASC 
           }),
           search.createColumn({
              name: "custrecord_maint_plan",
              join: "CUSTRECORD_CUSTOMER_UNIT",
              label: "Maintenance Plan"
           }),
           search.createColumn({
            name: "custrecord_maintenance_expire",
            join: "CUSTRECORD_CUSTOMER_UNIT",
            label: "Maintenance Plan Expiration"
          }),
           search.createColumn({
              name: "custrecord_equipment_model",
              join: "CUSTRECORD_CUSTOMER_UNIT",
              label: "Equipment Model",
              sort: search.Sort.ASC
           }),
           search.createColumn({
              name: "custrecord_purch_date",
              join: "CUSTRECORD_CUSTOMER_UNIT",
              label: "Purchase Date"
           }),
           search.createColumn({
              name: "custrecord_total_spent",
              join: "CUSTRECORD_CUSTOMER_UNIT",
              label: "Total amount spent on unit"
           }),
           search.createColumn({
            name: "custrecord_amt_remaining",
            join: "CUSTRECORD_CUSTOMER_UNIT",
            label: "Total amount remaining"
           }),
           search.createColumn({
            name: "formulatext",
            formula: "CASE WHEN {custrecord_customer_unit.custrecord_item_number}  LIKE '%LB%' THEN 'Lithium' ELSE NULL END",
            label: "Lithium"
           }),
           
        ]
     });






   var mySearchResults = mySNAR_Search.run().getRange(0,999);

   //create the HTML string to plop into RTF
   

   var strHTML = "<table border=2 cellpadding=8 cellspacing=2 class=”hoverTable” style=”width:500px”>";
   strHTML += "<tr><th><font size='4'>Serial</font></th><th><font size='4'>Status</font></th><th><font size='4'>Equip Type</font></th><th><font size='4'>Purchase Date</font></th><th><font size='4'>Total Spent</font></th><th><font size='4'>Total Remaining</font></th><th><font size='4'>Maintenance Plan</font></th><th><font size='4'>Maint Plan Exp Date</font></th><th><font size='4'>Lithium</font></th></tr>";


   //Loop through results adding to table

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

    var isDNR = mySearchResults[i].getText({
      name: "custrecord_unit_status",
      join: "CUSTRECORD_CUSTOMER_UNIT",
      label: "Unit Status"       
    });

    var isLith = mySearchResults[i].getText({
      name: "custrecord_item_number",
      join: "CUSTRECORD_CUSTOMER_UNIT",
      label: "Item Number"       
    });
    
    if (isDNR == 'DNR' || isDNR == 'RTDC'){

   strHTML += '<tr style="text-decoration: line-through;"><td>';
   
    } else {

    strHTML += '<tr><td>';
    }

    strHTML += mySearchResults[i].getValue({ 
        name: "name",
        join: "CUSTRECORD_CUSTOMER_UNIT",
        label: "Name"
     }),

    strHTML += '</td><td>';

    strHTML += mySearchResults[i].getText({ 
              name: "custrecord_unit_status",
              join: "CUSTRECORD_CUSTOMER_UNIT",
              label: "Unit Status"
           }),
    strHTML += '</td><td>';

    strHTML += mySearchResults[i].getText({ 
        name: "custrecord_equipment_model",
        join: "CUSTRECORD_CUSTOMER_UNIT",
        label: "Equipment Model"
     }),
    strHTML += '</td><td>';

    strHTML += mySearchResults[i].getValue({ 
        name: "custrecord_purch_date",
        join: "CUSTRECORD_CUSTOMER_UNIT",
        label: "Purchase Date"
     }),
    strHTML += '</td><td>';

    strHTML += mySearchResults[i].getValue({ 
        name: "custrecord_total_spent",
        join: "CUSTRECORD_CUSTOMER_UNIT",
        label: "Total amount spent on unit"
     });
     strHTML += '</td><td>';

     strHTML += mySearchResults[i].getValue({ 
        name: "custrecord_amt_remaining",
        join: "CUSTRECORD_CUSTOMER_UNIT",
        label: "Total amount remaining"
     }),
     strHTML += '</td><td>';
     
     strHTML += mySearchResults[i].getText({ 
      name: "custrecord_maint_plan",
      join: "CUSTRECORD_CUSTOMER_UNIT",
      label: "Maintenance Plan"
   }),
     strHTML += '</td><td>';
     
     strHTML += mySearchResults[i].getValue({ 
      name: "custrecord_maintenance_expire",
      join: "CUSTRECORD_CUSTOMER_UNIT",
      label: "Maintenance Plan Expiration"
   }),
     strHTML += '</td><td>';

     strHTML += mySearchResults[i].getValue({ 
      name: "formulatext",
      formula: "CASE WHEN {custrecord_customer_unit.custrecord_item_number}  LIKE '%LB%' THEN 'Lithium' ELSE NULL END",
      label: "Lithium"
     }),

    strHTML += "</td>";

   
   }

   strHTML += "</table>";


   currIncident.setValue({
       fieldId : 'custevent_equipment_details',
       value : strHTML
   });

} catch (e) {
   log.error(e.name);
   log.debug({
		title : 'Incident and Customer',
		details: "Incident = " + currIncident + " " + "Customer =" + currCustomer
		})
}
}
return {
    beforeSubmit : beforeSubmit
};

});
Even if that is in the context on the deployment?
b
log context.type
if its XEDIT, then you need to follow the help link i posted to learn about how to script xedits
m
Ok I will try that tomorrow. Thanks for your help!
b
misc note, you should probably log more than the name of the error in your logs, there is a message and stacktrace that tends to be more useful