Create a custom module.
/**
* To protect against version incompatibility, this script includes the @NApiVersion tag.
* myModule.js
* @NApiVersion 2.x
*/
//Custom Module .js file
define([], function() {
return {
}
});
* To protect against version incompatibility, this script includes the @NApiVersion tag.
* myModule.js
* @NApiVersion 2.x
*/
define(['N/runtime'], function (runtime) {
//Create your own function
function gettingUserName() {
var userName = runtime.getCurrentUser().name;
return userName;
}
return {
gettingUserName: gettingUserName
};
});
Place the file inside SuiteScripts folder and note down the path where you place the file.
Example: I have placed the custom module file in SuiteScripts/module
My path is SuiteScripts/module/myModule.js
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(['SuiteScripts/module/myModule', 'N/ui/message'], function (myModule, message) {
function pageInit(context) {
// Calling my custom module function
var name = myModule.gettingUserName();
var myMsg = message.create({
title: "My Title",
message: "My Name is" + name,
type: message.Type.CONFIRMATION
});
// will disappear after 5s
myMsg.show({
duration: 5000
});
}
return {
pageInit: pageInit
};
});
Create and deploy the above ClientScript Code and check the Output.