Add a Dynamic Link to a List in a Suitelet

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript Debugger.

The code sample shown on this page adds a dynamic link, in this case, an entity record Dashboard, to a custom list column in a Suitelet.

Note:

For steps to create a custom list, see SuiteScript Debugger

We added the link using a View Dashboard icon. This icon shows when you hover over a record in any entity list (for example, Customers, Prospects, Leads, which you can view in List > Relationship). When you click the icon, it will direct you to a Dashboard page for that particular record.

The following steps show how to add the View Dashboard icon which will link an entity record with the corresponding Dashboard to a list in a Suitelet:

Add a View Dashboard Icon

  1. Create a Transaction Body Field:

    1. Go to Customization > Lists, Records, & Fields > Transaction Body Fields > New.

    2. In Basic Information fill in the following fields:

      • In Label, enter: Dashboard.

      • In Image ID, enter: _dashboard_image.

      • In Type, select: Free-Form Text.

      • in Store Value: don’t check the box.

    3. In Validation & Defaulting tab fill in the following fields:

      • In Default Value, enter (including the single quotation marks): '<img src="/images/nav/ns_x.gif" height="13" width="16" border="0" title="View Dashboard" class="i_dashboard_gray">'.

      • In Formula: check the box.

    4. Click Save.

  2. Deploy Suitelet script:

    1. Create a JavaScript file named "SuiteletDashboard.js" with the following code:

                          /**
       * @NApiVersion 2.x
       * @NScriptType Suitelet
       * @NModuleScope SameAccount
       */
      define(["N/ui/serverWidget","N/search"],
      
      function(serverWidget,search) {
          function demoList(context) {
              var list = serverWidget.createList({
                  title: 'Simple List'
              });
              list.style = context.request.parameters.style;
              var column = list.addColumn({
                  id: 'custbody_dashboard_image',
                  label: 'Dashboard',
                  type: serverWidget.FieldType.TEXT,
                  align: serverWidget.LayoutJustification.LEFT
              });
              column.setURL({
                  url:"https://system.netsuite.com/app/center/card.nl?sc=-69" //URL of a Dashboard
              });
              column.addParamToURL({ 
                  param: 'entityid', 
                  value: 'entity',
                  dynamic: true // the dynamic parameter that allows to link the URL of a Dashboard with the corresponding entity
              });
              list.addColumn({
                  id: 'trandate',
                  label: 'date',
                  type: serverWidget.FieldType.DATE,
                  align: serverWidget.LayoutJustification.LEFT
              });
              list.addColumn({
                  id: 'name_display',
                  label: 'Customer',
                  type: serverWidget.FieldType.TEXT,
                  align: serverWidget.LayoutJustification.LEFT
              });
              list.addColumn({
                  id: 'salesrep_display',
                  label: 'Sales Rep',
                  type: serverWidget.FieldType.TEXT,
                  align: serverWidget.LayoutJustification.LEFT
              });
              list.addColumn({
                  id: 'amount',
                  label: 'Amount',
                  type: serverWidget.FieldType.CURRENCY,
                  align: serverWidget.LayoutJustification.RIGHT
              });
      
              var searchEstimate = search.create({
                  type: search.Type.ESTIMATE,
                  filters: [{
                      name: 'mainline',
                      operator: 'is',
                      values: ['T']
                  }],
                  columns: [{
                      name: 'trandate'
                  }, {
                      name: 'entity'
                  }, {
                      name: 'name'
                  }, {
                      name: 'salesrep'
                  }, {
                      name: 'amount'
                  }, {
                      name: 'custbody_dashboard_image'    // Dashboard link
                  }],
              });
              var searchEstimateResults = searchEstimate.run();
              var results = searchEstimateResults.getRange({
                  start: 0,
                  end: 1000
              });
              list.addRows({
                  rows: results
              });
      
              context.response.writePage({
                  pageObject: list
              });
          }
      
          return {
              onRequest: demoList
          };
      }); 
      
                        
    2. Go to Customization > Scripting > Scripts > New.

    3. Click +.

    4. Upload JavaScript file from Step 1.

    5. Click the Create Script Record button.

    6. In Basic Information, in the Name field, enter: View Dashboard Suitelet.

    7. In Deployments tab, enter:

      • Title: View Dashboard Suitelet

      • Status: Released

    8. Click Save.

Troubleshooting

The following table shows errors that you might get while adding a creating a Transaction Body Field:

Error message

Solution

Your formula has an error in it. It could resolve to the wrong datatype, use an unknown function, or have a syntax error. Please go back, correct the formula, and re-submit.

Include single quotation marks when entering the value in the Default Value field (step 1c): '<img src="/images/nav/ns_x.gif" height="13" width="16" border="0" title="View Dashboard" class="i_dashboard_gray">'

General Notices