dennysutanto
04/13/2025, 2:07 PMCeligo AI
04/13/2025, 2:07 PMAI generated answer (using internal Slack threads):To trigger a client script function on record load, you can use the
pageInit
function in your client script. This function is automatically triggered when a record is loaded.
Here is an example of how you can define this function in your client script:
javascript
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/record'],
function(record) {
function pageInit(scriptContext) {
// Your code here
}
return {
pageInit: pageInit,
};
});
In the pageInit
function, you can add the code that you want to execute when the record is loaded.
However, if you want to trigger a function on a button click, you can add a button in the beforeLoad
function of your User Event script and set the functionName
property to the name of the function in your client script that you want to trigger. Here is an example:
javascript
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record'],
function(record) {
function beforeLoad(context) {
if(context.type != context.UserEventType.VIEW) {
var newSoRecord = context.newRecord;
context.form.clientScriptFileId = 427704;
context.form.addButton({
id: "custpage_calculatecommission",
label: "Calculate Commission",
functionName: "calculatecommission"
});
}
}
return {
beforeLoad: beforeLoad,
};
});
In this example, when the button with the id custpage_calculatecommission
is clicked, the calculatecommission
function in your client script will be triggered.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
04/13/2025, 2:07 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.823576
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.818756461
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816433489
Celigo AI
04/13/2025, 2:07 PM