How can I debug why 1 script is stopping another s...
# suitescript
p
How can I debug why 1 script is stopping another script from working. I have 1 script that is in 1.0 that does a calculation on a sublist that is deployed to Sales Order. I have another script that is in 2.0 that does a search and populates fields in the main sales order form. The scripts do not reference any of the same fields and the only thing they have in common is that they are both field change scripts. Any ideas?
b
you can use literal debugger; statements to use the console debugger
or you can share the code
p
using the debugger did not help becasue the 1 script (the 2.0) does not fire at all when the 1.0 script is deployed.
will post code shortly.
1.0 script
function bkWeightCalc(type, name){
if ((type == 'recmachcustrecord_dims_so') && ((name == 'custrecord_dims_quantity' ) || (name == 'custrecord239'))) {
var qty = parseFloat(nlapiGetCurrentLineItemValue('recmachcustrecord_dims_so', 'custrecord_dims_quantity'));
var weight = parseFloat(nlapiGetCurrentLineItemValue('recmachcustrecord_dims_so', 'custrecord239'));
if (qty > 0) {
var ttlweight = qty * weight;
}
else {
}
nlapiSetCurrentLineItemValue('recmachcustrecord_dims_so', 'custrecord240', ttlweight);
}
};
Copy code
/**
    *@NApiVersion 2.0
    *@NScriptType ClientScript
    */
define(['N/record','N/search', 'N/ui/dialog'], function (r,search,u) {
    function fieldChanged2(context) {
        
var recCurrent = context.currentRecord;
if ((context.fieldId == 'custbody_select_contact_final')||(context.fieldId == 'custbody_select_venue_final')||(context.fieldId == 'custbody_select_agent_consol_final')||(context.fieldId == 'custbody_address_label_final')) {
    var myContact = recCurrent.getValue({ fieldId: 'custbody_select_contact_final'});
    var myVenue = recCurrent.getValue({ fieldId: 'custbody_select_venue_final'});
    var myConsol = recCurrent.getValue({ fieldId: 'custbody_select_agent_consol_final'});
    var myOther = recCurrent.getValue({ fieldId: 'custbody_select_other_customer_final'});
    var myAddressId = recCurrent.getText({ fieldId: 'custbody_address_label_final'});
    var addressSource = recCurrent.getText({ fieldId: 'custbody_final_address_source'});
    var pickupAddress = recCurrent.getField({ fieldId: 'custbody_final_delivery_address'});

if (addressSource == "Select Via Contact Name") {
    recCurrent.getField({ fieldId: 'custbody_select_venue_final'}).isDisplay = false;
    var s = search.create({
        type: search.Type.CONTACT,
        columns: [
            search.createColumn({name: "address"}),
            search.createColumn({name: "entityid"}),
            search.createColumn({name: "phone"})
        ],
        filters : [['internalid', 'is', myContact]] 
    });
    
    var pagedData = s.runPaged({pageSize: 1000});
    
    // iterate the pages
    for( var i=0; i < pagedData.pageRanges.length; i++ ) {

        // fetch the current page data
        var currentPage = pagedData.fetch(i);

        // and forEach() thru all results
        currentPage.data.forEach( function(result) {

            // you have the result row. use it like this....
            var address = result.getValue('address');
            var ctcname = result.getValue('entityid');
            var ctcphone = result.getValue('phone');
            recCurrent.setValue({ fieldId: 'custbody_final_delivery_address',value: address});
            recCurrent.setValue({ fieldId: 'custbody_contact_final',value: ctcname});
            recCurrent.setValue({ fieldId: 'custbody_final_contact_phone',value: ctcphone});  
        log.debug({
    title: 'Contact Name', 
    details: ctcname
});      
    });

    }
    }
    else
        if (addressSource == "Select Venue / Advance Warehouse") {
    var sv = search.create({
   type: "customrecord_eym_show_venue",
        columns : [
      search.createColumn({name: "custrecord_eym_sv_full_address", label: "Venue Full Address"}),
      search.createColumn({name: "custrecord_eym_sv_contactname", label: "Contact Name"}),
      search.createColumn({name: "custrecord_eym_sv_contact_phone", label: "Phone"})
        ],
        filters : [['internalid', 'is', myVenue]] 
    });
    
    var pagedData = sv.runPaged({pageSize: 1000});
    
    // iterate the pages
    for( var i=0; i < pagedData.pageRanges.length; i++ ) {

        // fetch the current page data
        var currentPage = pagedData.fetch(i);

        // and forEach() thru all results
        currentPage.data.forEach( function(result) {

            // you have the result row. use it like this....
            var venue = result.getValue('custrecord_eym_sv_full_address');
            var venuectc = result.getValue('custrecord_eym_sv_contactname');
            var venuephone = result.getValue('custrecord_eym_sv_contact_phone');
            recCurrent.setValue({fieldId: 'custbody_final_delivery_address',value: venue});
            recCurrent.setValue({fieldId: 'custbody_contact_final',value: venuectc});
            recCurrent.setValue({fieldId: 'custbody_final_contact_phone',value: venuephone});        
        });

    }
    }
        else
        if (addressSource == "Select Agent / Consolidation Point") {
    var sc = search.create({
   type: "customrecord_eym_show_venue",
        columns : [
              search.createColumn({name: "custrecord_eym_sv_full_address", label: "Venue Full Address"}),
      search.createColumn({name: "custrecord_eym_sv_contactname", label: "Contact Name"}),
      search.createColumn({name: "custrecord_eym_sv_contact_phone", label: "Phone"})
        ],
        filters : [['internalid', 'is', myConsol]] 
    });
    
    var pagedData = sc.runPaged({pageSize: 1000});
    
    // iterate the pages
    for( var i=0; i < pagedData.pageRanges.length; i++ ) {

        // fetch the current page data
        var currentPage = pagedData.fetch(i);

        // and forEach() thru all results
        currentPage.data.forEach( function(result) {

            // you have the result row. use it like this....
            var consol = result.getValue('custrecord_eym_sv_full_address');
            var consolctc = result.getValue('custrecord_eym_sv_contactname');
            var consolphone = result.getValue('custrecord_eym_sv_contact_phone');
            recCurrent.setValue({fieldId: 'custbody_contact_final',value: consolctc});
            recCurrent.setValue({fieldId: 'custbody_final_contact_phone',value: consolphone});
            recCurrent.setValue({fieldId: 'custbody_final_delivery_address',value: consol});        
        });
    }
    }
        else
        if (myAddressId) {
    var sd = search.create({
     type: "customer",
    filters:
       [
      ["address.addresslabel","is",myAddressId], 
      "AND", 
      ["internalid","anyof",myOther]
   ],
    columns:
    [
      search.createColumn({name: "companyname", label: "Company Name"}),
      search.createColumn({name: "internalid",join: "Address",}),
      search.createColumn({name: "address",join: "Address",}),
      search.createColumn({name: "attention",join: "Address",}),
      search.createColumn({name: "addressphone",join: "Address",})
   ]
    });
    var pagedData = sd.runPaged({pageSize: 1000});
    
    // iterate the pages
    for( var i=0; i < pagedData.pageRanges.length; i++ ) {

        // fetch the current page data
        var currentPage = pagedData.fetch(i);

        // and forEach() thru all results
        currentPage.data.forEach( function(result) {

            // you have the result row. use it like this....
            var othaddress = result.getValue({name: 'address',join: 'Address'
            });
            var othcontact = result.getValue({name: 'attention',join: 'Address'
            });
            var othphone = result.getValue({name: 'addressphone',join: 'Address'
            });    
            recCurrent.setValue({fieldId: 'custbody_final_delivery_address',value:othaddress
             });        
            recCurrent.setValue({fieldId: 'custbody_contact_final',value:othcontact
             });
            recCurrent.setValue({fieldId: 'custbody_final_contact_phone',value:othphone
             });            
        });

    }
    }
/*End searches */
}}
return {
            fieldChanged: fieldChanged2
};
    });
s
Someone mentioned a while back that they had trouble when they had both a 1.0 and 2.0 client script deployed on the same record. I can’t remember the full details, but something was different with the page when the 1.0 client script was deployed, and that difference prevented the 2.0 script from working. Try saving the full web page (html output) with the 1.0 script deployed, and then again undeployed, and then do a diff of the generated html to see what is different. It might help pinpoint the issue.
b
too much code to be debugging an issue as simple as a function not fireing
id remove everything and just leave it as a lone line console.debug
s
If you just pare the 1.0 script down to:
and the 2.0 code down to:
It might simplify debugging which of either methods is firing
I have tested and seen that when there is both a 1.0 and 2.0 script, both with validateField functions, only the 1.0 function executes. The same could be happening for other entry points.
r
You also might want to check if you have exceeded the 10 client script limit on the record. If your 2.0 code is the 11th script deployed, it wont execute.
p
that was it. Was not aware I was passed the 10 limit. time to combine some scripts. thanks.