Hi
We have recently enabled the SuiteBilling module in NetSuite and also added in the Subscription Billing Enhanced UI.
I have been asked by Finance if I can add all the recurring amount values for active subscriptions and put the value into the a Monthly Total field, so its easy to see how much a customer is paying per month.
I have done a similar thing on sales orders, but I dont know how to reference the subscription fields i need.
I have attempted a script, but it would load and fails.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/record'],
function (record) {
function afterSubmit(context){
//CALCULATE MONTHLY COST ON SUBSCRIPTION
if(context.type !== context.UserEventType.DELETE){
//Set pointer to current record
var recordID = context.newRecord.id;
var loadrec = record.load({
type: 'subscription',
id: recordID,
isDynamic: false
});
//Loop through all line items and add up the recurring amount
var itemcount = loadrec.getLineCount('subscriptionline')
var monthlycost = 0
for (var i=0;i<itemcount;i++){
if (loadrec.getSublistValue({sublistId:'subscriptionline',fieldId:'status',line:i}) = 'Active'){
monthlycost = monthlycost + loadrec.getSublistValue({sublistId:'lines',fieldId:'recurringamount',line:i})
}
}
loadrec.setValue({
fieldId: 'custrecord_monthlycost',
value: monthlycost
})
loadrec.save()
}
return true
loadrec.save()
}
return{afterSubmit: afterSubmit}
}
)
The above fails with this.
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"SyntaxError","message":"SyntaxError: /SuiteScripts/UE - Subscriptions - After Submit.js:21:24 Invalid left hand side for assignment\n if (loadrec.getSublistValue({sublistId:'subscriptionline',fieldId:'status',line:i}) = 'Active'){\n ^\n/SuiteScripts/UE - Subscriptions - After Submit.js:25:16 Expected , but found loadrec\n loadrec.setValue({\n ^\n/SuiteScripts/UE - Subscriptions - After Submit.js:27:25 Expected ; but found :\n value: monthlycost\n ^\n/SuiteScripts/UE - Subscriptions - After Submit.js:28:16 Expected eof but found }\n })\n ^\n [if (loadrec.getSublistValue({sublistId:'subscriptionline',fieldId:'status',line:i}) = 'Active'){, ^, /SuiteScripts/UE - Subscriptions - After Submit.js:25:16 Expected , but found loadrec]","stack":["SyntaxError: /SuiteScripts/UE - Subscriptions - After Submit.js:21:24 Invalid left hand side for assignment"," if (loadrec.getSublistValue({sublistId:'subscriptionline',fieldId:'status',line:i}) = 'Active'){"," ^","/SuiteScripts/UE - Subscriptions - After Submit.js:25:16 Expected , but found loadrec"," loadrec.setValue({"," ^","/SuiteScripts/UE - Subscriptions - After Submit.js:27:25 Expected ; but found :"," value: monthlycost"," ^","/SuiteScripts/UE - Subscriptions - After Submit.js:28:16 Expected eof but found }"," })"," ^",""]}