Hi I am total novice at suitecripting but I wanted...
# suitescript
a
Hi I am total novice at suitecripting but I wanted to do something simple like our finance wants to have 2 fields on Quotes, Sales Orders and Invoices that show a 3% fee of the total and a new total field that shows the total with the fee *also i ve limited it to just 1 subsidiary (internal code 2). So i figured simple to get my feet wet in suite scripting and since those fields do not touch anything then i wont be impacting much. I created this script and deployed to those 3 record types and the 2 custom fields (custbody_custom_totalwfee and custbody_custom_totalwfee) are displayed on the forms . It works for Quotes but not Sales orders or Invoices. I cant seem to figure out what ive missed? any suggestions? (I used code snippets in VS to start me off then added what I wanted and used ChatGPT 4o to help with cleaning up the my original code). /** * @NApiVersion 2.x * @NScriptType ClientScript */ define(['N/record', 'N/log'], function(record, log) { function calculateProcessingFee(context) { var currentRecord = context.currentRecord; var subsidiary = currentRecord.getValue({ fieldId: 'subsidiary' }); log.debug('calculateProcessingFee', 'Subsidiary: ' + subsidiary); // Check if the subsidiary is Internal ID: 2 if (subsidiary == 2) { var total = currentRecord.getValue({ fieldId: 'total' }); log.debug('calculateProcessingFee', 'Total: ' + total); if (total) { var fee = total * 0.03; currentRecord.setValue({ fieldId: 'custbody_credit_card_fee', value: fee }); log.debug('calculateProcessingFee', 'Credit Card Fee: ' + fee); var customTotal = total + fee; currentRecord.setValue({ fieldId: 'custbody_custom_totalwfee', value: customTotal }); log.debug('calculateProcessingFee', 'Custom Total with Fee: ' + customTotal); } else { log.debug('calculateProcessingFee', 'Total is not defined'); } } else { log.debug('calculateProcessingFee', 'Subsidiary does not match'); } } function fieldChanged(context) { var fieldId = context.fieldId; log.debug('fieldChanged', 'Field ID: ' + fieldId); alert('Field Changed: ' + fieldId); // Alert added for debugging if (fieldId === 'total' || fieldId === 'subsidiary') { calculateProcessingFee(context); } } function saveRecord(context) { log.debug('saveRecord', 'Save Record Triggered'); alert('Save Record Triggered'); // Alert added for debugging calculateProcessingFee(context); return true; } return { fieldChanged: fieldChanged, saveRecord: saveRecord }; });
I've checked the execution logs and nothing under each corresponding deployment. I've added debugger; and used Chromes dev tools to debug and it never gets triggered. actually even loading the sales order or invoice I do not see my script even pulled up in the window. I do see it when i load a new quote.
e
Only asking this because I've made this mistake many times. Have you made sure the script is deployed properly to all of those transaction types?
a
thats a good question (stupid question coming) Other than redeploying it how do I check?
I really do feel like thats what has happened like its not deployed for those 2
e
Customization > Scripting > Scripts
Find your client script. Check the Deployments tab. You should see a deployment for any transaction type you want it to run on.
a
Also Ive made sure my role and ive listed under the audience tab *ive also tried all roles and all employees.
from what I see its there and the script is referenced as it should
z
Hi @Arthur B., If the script is deployed correctly, then set the priority of your client script to run it first by going to script records (as shown below) and try to find out if any other script is preventing it to run or not.
👍 1
s
I'd recommend doing this as a server script rather than client script unless this is explicitly meant for humans to see on the screen as they interact.
👍 1
a
Thank You to all of you. there was a few issues. 1. on Sales orders we did have a few other things running and therefore my script was running last and the script prior was saving changes so I assume after it was done and record was saved then it had no reason to trigger my save record. 2. I was doing it as a client script and changed it to the user event and I was able to get it all smoothed out. Thank You for the suggestions!!!
🎉 1