-1
function() {
    function render(params) 
    {
        params.portlet.title = 'My Portlet';
        var content = '<body>'+
        '<form>' +
          ' <fieldset>'+
             ' <legend>Selecting elements  </legend> ' +
              '<p>  <label>Select Range</label>  <select id = "myList"><option value = "1">Daily</option> <option value = "2">Weekly</option>'+
                  ' <option value = "3">Monthly</option>  <option value = "4">Yearly</option>' +
                ' </select>' +
             ' </p>' +
          ' </fieldset>' +
        '</form>' +
     ' </body>';
        params.portlet.html = content;
    }

Can you guys help me in writing code for pie chart . and provide me some syntax for calling other scripts from portlet.

I've tried adding a select field( Drop down) using html in netsuite and it is working fine. But i want pie chart in my UI.

Robert
  • 7,394
  • 40
  • 45
  • 64

1 Answers1

2

NetSuite runs JavaScript/HTML/CSS like everything else. I would make an HTML file holding everything you need (JavaScript, CSS, and any plotting libraries), and open it with localhost to check things out. When you have that the way you like it, pick the option that works for you to port that into NetSuite:

  1. Copy the text to var content = "your_html_here" (will likely be a pain to maintain but will work fine).

  2. Load the HTML file into your file cabinet, and load it into your portlet script to do text replacing to insert any data you need (one extra step, but much easier to maintain and you can pull down the HTML file to do any local testing you need):

var content = file.load({id: /Suitescripts/path_to_your_html_file.html"}).getContents()

content = content.replace("Placeholder_Text", "With This")

Since you're asking how to build a pie chart, I would recommend using something like d3js where you might be able to build off this example of a pie chart.

If you get stuck, or need some help, comment back down below. There's no such thing as a stupid question, promise!

EDIT

You asked about adding search results to your HTML file. Although it sounds like you've answered your question, I will document the process here just in case, never know whose coming here from Google!

var mySearch = search.load({id: "my_search_id", ...})

mySearch.run.each(function(result) {
  searchHTML += "<tr>"
  searchHTML += `<td>${result.getText({name: "fieldname", ... })}</td>`
  searchHTML += `<td>${result.getValue({name: "fieldname", ... })}</td>`
  searchHTML += "</tr>"

  // To move onto the next result
  return true;
})

Hope that helps!

zerecees
  • 697
  • 4
  • 13
  • Thats great, it works . tq so much for the code and also how can i add my script values( search result values) to this html code so that respective values will reflect on my pie chart. Please help me with this. – Mr Explorer Apr 08 '20 at 21:14
  • I've used content.replace and Thats Great!!! It Works....Thank you so much for the code...........really a big thanks – Mr Explorer Apr 08 '20 at 21:37
  • Hi @SanthoshKumar, I added some work to my answer. Hope it's useful! – zerecees Apr 10 '20 at 03:10
  • Hi @zerecees can you please clarify me one more doubt if u dont mind....How can i add library files in my script so that pie chart will be displayed fully with animations.? – Mr Explorer Apr 11 '20 at 05:22
  • Hi @SanthoshKumar! You can upload any library to the file cabinet and reference it in SuiteScript as long as it is an [AMD](https://stackoverflow.com/a/10160533/11323304) compatible library. Let's say I was using [Lodash](https://lodash.com/); upload to file cabinet and then write `define(["/SuiteScripts/path/to/lodash.js"], function(_) {...})` (Lodash syntax is to use "_", similar to "$" in jQuery). But, since you're using HTML, I would advise doing it by CDN in your `` tags. That way, you can do everything through HTML and not the file cabinet. Does that help? – zerecees Apr 12 '20 at 05:47
  • Hi @zerecees, One last question....i have a dropdown list in my HTML file....when i select a value from the dropdown list, i should retrieve the value from the list and process according to the selection..................how can i write a code in suitescript so that i can retrieve the value from HTML and process accordingly......plz do help in this....Thanks for all the help you did till now. – Mr Explorer Apr 13 '20 at 11:58
  • Hello! I’m writing a post back to another user, and it’s going take some some time to get it squared away. However, the quickest advice I can give you is to look at the NetSuite help documentation for creating a Suitelet. They have an example with a customer service survey where they get the data and bring it to NetSuite. I forget exactly how, though. If you are doing it in an HTML file, not an HTML field in your suitelet, I would use something like jQuery and interact with only the HTML. Otherwise, you may have to do an auth token to talk to NetSuite, which I am not an expert in. – zerecees Apr 14 '20 at 22:37