Portlet Script Samples

For help with writing scripts in SuiteScript 2.x, see SuiteScript 2.x Hello World and SuiteScript 2.x Entry Point Script Creation and Deployment.

Simple Form Portlet Script Sample

This sample creates a portlet that includes a simple form with a text field and a submit button.

            /**
 * @NApiVersion 2.x
 * @NScriptType Portlet
 */

define([], function() { 
        function render(params) { 
            var portlet = params.portlet; 
            portlet.title = 'Simple Form Portlet'; 

            var fld = portlet.addField({ 
                id: 'text', 
                type: 'text', 
                label: 'Text' 
            }); 
            
            fld.updateLayoutType({ 
                layoutType: 'normal' 
            }); 

            fld.updateBreakType({ 
                breakType: 'startcol' 
            }); 
            
            portlet.setSubmitButton({ 
                url: 'http://httpbin.org/post', 
                label: 'Submit', 
                target: '_top' 
            }); 
        } 
        
        return { 
            render: render 
        };
}); 

          

Inline HTML Portlet Script Sample

This sample creates a portlet that displays simple HTML.

            /**
 * @NApiVersion 2.x
 * @NScriptType Portlet
 */

define([], function() { 
    function render(params) { 
        params.portlet.title = 'My Portlet'; 
        var content = '<td><span><b>Hello!!!</b></span></td>'; 
        params.portlet.html = content; 
    } 
    
    return { 
        render: render 
    };
}); 

          

Links and Indents Portlet Script Sample

This sample creates a portlet with two links.

            /**
 * @NApiVersion 2.x
 * @NScriptType Portlet
 */

define([], function() { 
    function render(params) { 
        var portlet = params.portlet; 
        portlet.title = 'Search Engines'; 
        portlet.addLine({ 
            text: 'NetSuite', 
            url: 'http://www.netsuite.com/' 
        }); 
        portlet.addLine({ 
            text: 'Oracle', 
            url: 'http://www.oracle.com/' 
        }); 
    } 
    
    return { 
        render: render 
    };
}); 

          

Simple List Portlet Script Sample

This sample creates a portlet with a simple list.

Important:

This sample references a custom entity field with the ID custentity_multiselect. Before attempting to use this sample, you must either create a field with that ID or edit the sample so that it references an existing custom entity field in your account. To create a custom entity field, see Creating Custom Entity Fields.

            /**
 * @NApiVersion 2.x
 * @NScriptType Portlet
 */

define(['N/search'], function(search) { 
    function render(params) {
        // Check if the portlet is placed in the center column 
        var isDetail = (Number(params.column) === 2); 
        var portlet = params.portlet; 

        // Set the portlet title based on the column it is placed in
        portlet.title = isDetail ? "My Detailed List" : "My List"; 
        
        // Add columns to the portlet
        portlet.addColumn({ 
            id: 'internalid', 
            type: 'text', 
            label: 'ID', 
            align: 'LEFT' 
        }); 
        
        portlet.addColumn({ 
            id: 'companyname', 
            type: 'text', 
            label: 'Company Name', 
            align: 'LEFT' 
        }); 
        
        // If the portlet is in the center column, add extra columns
        if (isDetail) { 
            portlet.addColumn({ 
                id: 'email', 
                type: 'text', 
                label: 'E-mail', 
                align: 'LEFT' 
            }); 
            portlet.addColumn({ 
                id: 'custentity_multiselect', 
                type: 'text', 
                label: 'Multiselect', 
                align: 'LEFT' 
            }); 
        }
        
        // Create a filter for the search to find customers with non-empty email field
        var filter = search.createFilter({ 
            name: 'email', 
            operator: search.Operator.ISNOTEMPTY 
        });
        
        // Create a customer search with the specified columns
        var customerSearch = search.create({ 
            type: 'customer', 
            filters: filter, 
            columns: ['internalid', 'companyname', 'email', 'custentity_multiselect'] 
        });
        
        // Set the number of rows to show in the portlet based on the column it is placed in
        var count = isDetail ? 15 : 5;
        
        // Run the search and add the results to the portlet
        customerSearch.run().each(function(result) { 
            portlet.addRow(result.getAllValues()); 
            return --count > 0; 
        }); 
    } 
    
    return { 
        render: render 
    };
}); 

          

Related Topics

General Notices