Create a custom library module in SuitScript 2.0
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 {
        
    }
});

Now add your own function to the code.( Or copy the below code )
 * 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
Now import the custom module to your Script.
This example uses the define Function to include a native SuiteScript module and a custom module. The module’s file path is used to pass in the custom utility as a dependency. As a best practice, it does not include the .JS file extension.
/**
 *@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.
Coming Soon...
Free Web Hosting