TexasSwede
texasswede@gmail.com
  • About this blog
  • My Website
  • My Resume
  • XML Export Tool
  • Photos

Monthly Archives: July 2017

Will I see you at MWLUG?

Posted on July 26, 2017 by Karl-Henry Martinsson Posted in #IBMChampion, Community, IBM/Lotus, MWLUG, Notes/Domino Leave a comment

It is less than 2 weeks left to MWLUG 2017, an outstanding Conference that I will be attending for the third year. This will also be the third year I will be speaking, and this time it will be a brand new presentation. My session, AD103, will be on Tuesday, August 8 at 5pm.

I hear that there are still a couple of openings left. If you have attended a previous MWLUG conference you are entitled to 25% off the registration fee of $100. But even at $100 this is a great deal, with over 50 sessions and much more.

So what are you waiting for? Register, and I will see you in two weeks in Alexandria, VA!

A few openings left for MWLUG 2017 

Posted on July 17, 2017 by Karl-Henry Martinsson Posted in #IBMChampion, Community, IBM/Lotus, MWLUG, Programming Leave a comment

There are a a few openings available for MWLUG in a couple of weeks. The conference is taking place August 8-10 in Alexandria, VA. It is shaping up to be a great experience, with over 50 sessions, two free workshops  as well as social events and two round table discussions with IBM on the future of development. Among the many great presenters you will find 20 IBM Champions, as well as several IBMers.

The early bird registration has expired, but if you are a previous attendee, you get $25 off the regular price of $100. If you haven’t registered yet, don’t miss out on this great conference!

I hope to see you at MWLUG. My session Elementary – Incorporating BlueMix, Node-RED and Watson in Domino applications will be Tuesday, August 8 at 5pm.

Load and Modify External File in NetSuite

Posted on July 7, 2017 by Karl-Henry Martinsson Posted in Bootstrap, HTML/CSS, Javascript, jQuery, NetSuite, Programming, SuiteScript, Web Development Leave a comment

When building a suitelet in NetSuite you can either inject HTML, CSS and Javascript in a field, or generate a full HTML page and render it into the suitelet. No matter which method you use, you normally have to write line after line of SuiteScript code where you build the HTML using string concatenation. This is not only difficult and tedious to write, making sure you match all the single and double quotes and semi colons, it also makes the code much harder to maintain.

What if you could just create a regular HTML file, put it in the File Cabinet and then render it into a suitelet? And what if you could use one line of code to inject values from NetSuite in the correct place in the HTML? This could be search results from the use of my search function.

That is what the function looks like:

/**
 * Load file from NetSuite File Cabinet and replace placeholders with actual values
 * 
 * Version    Date            Author           Remarks
 * 1.00       07 Nov 2016     kmartinsson      Created class/function
 * 1.01       08 Nov 2016     kmartinsson      Consolidated setValue and setHTML into
 *                                             one method and added noEscape parameter
 */
// ***** Read and process external file, replacing placeholders with proper values *****
function ExternalFile(filename) {
   //Get the file by path/name, can also be internal id
   var fileId = filename;
   // Load file content and store data
   var file = nlapiLoadFile(fileId);
   var data = file.getValue();
   this.content = data;

   this.setValue = function(placeholder, value, noEscape) {
      // Check if noEscape is passed, if it is and if true then don't escape value.
      // This is needed when value contains HTML code.
      if (typeof noEscape == "undefined") {
         this.content = this.content.replace(new RegExp(placeholder, 'g'), nlapiEscapeXML(value));
      } else {
         if (noEscape == true) {
            this.content = this.content.replace(new RegExp(placeholder, 'g'), value);
         } else {
            this.content = this.content.replace(new RegExp(placeholder, 'g'), nlapiEscapeXML(value));
         }
      }
   }

   this.getContent = function() {
      return this.content;
   }
}

Reference this function in your Suitescript 1.0 code like this:

// Load extrenal HTML file
var html = new ExternalFile("SuiteScripts/BinTransfer.html");
// Insert NetSuite URL for CSS files
var cssFileName = nlapiLoadFile("SuiteScripts/css/drop-shadow.css").getURL();
html.setValue("%cssDropShadow%", cssFileName, true);
cssFileName = nlapiLoadFile("SuiteScripts/css/animate.css").getURL();
html.setValue("%cssAnimate%", cssFileName, true);
// Insert array returned from a search
html.setValue("%binarray%", JSON.stringify(binArray), true);
// Replace placeholders with values
html.setValue("%showAll%", "false");
html.setValue("%company%", companyName);

The last (optional) argument “noEscape” decides if the value should be URL encoded (false/omitted) or not (true) using the function nlapiEscapeXML(). In most cases you don’t need to specify this argument, but if you need to pass HTML or other code into the function you need to set it to true to avoid the code being modified.

As you can see in my example above, I get the NetSuite URL for my CSS files as well. Instead of hard coding the NetSuite URL into the HTML page, I calculate it and insert it when the page is loaded. Not only does it make the page easier to read the code, it also makes it much easier to maintain.

This is a snippet from the HTML file:

<!-- Load plugins/drop-shadow.css from File Cabinet -->
<link href="%cssDropShadow%" rel="stylesheet">
<!-- Load bootstrap-notify.js and animate.css from File Cabinet -->
<script src="%jsBootstrapNotify%"></script>
<link href="%cssAnimate%" rel="stylesheet">

Much easier to read!

Thanks to this little function I have built suitelets who does nothing but load a traditional HTML file with Bootstrap, jQuery, even jQuery Mobile for mobile devices. The page contains Javascript/jQuery that call RESTlest to read and write data. Now I can build suitelets with all the power I have in traditional web development at the same time as I get access to the full NetSuite functionality!

This can also be used to generate XML files to convert into PDF.

Happy coding!

 

MWLUG 2017 – Be There!

Posted on July 6, 2017 by Karl-Henry Martinsson Posted in #IBMChampion, Community, IBM/Lotus, MWLUG Leave a comment


This year’s MWLUG conference will take place in Alexandria, VA. During the three day conference more than 50 sessions and two free workshops will be offered. All this for just $75.

This year the conference starts a day earlier than usual, on a Tuesday. But everything you are used to from the previous years will be there. Keynotes, sessions, workshops, breakfast and lunch, receptions, networking events, access to experts, and much more. A new even for this year is Linuxfest, known from Lotusphere/IBM Connect. It is again hosted by Bill Malchisky together with a (as of now) secret guest speaker.

You can register for MWLUG 2017 here.

Easy NetSuite Search

Posted on July 5, 2017 by Karl-Henry Martinsson Posted in Javascript, NetSuite, Programming, SuiteScript 1 Comment

In an attempt to expand my knowledge to other platforms than Notes and Domino, I have now been working with NetSuite for a number of months. I have mainly been working with the ERP part of the cloud based system.

The language used is called SuiteScript, and it is Javascript with a NetSuite-specific API to work directly with the databases. Knowing Javascript makes it easy to get started, just like knowing Visual Basic makes it easy to learn Lotusscript. And just like with Lotusscript, you have to learn the NetSuite specific functions.

Since I like my code clean and easy to read (which will make future maintenance easier), I have created a number of functions to encapsulate NetSuite functionality.

The first one I created was to search the database. The search in NetSuite is done by defining the columns (i.e. fields) to return as an array of search column objects. Then an array of search filters is created, and finally the search function is called, specifying what record type to search and passing the two arrays to it as well. This is a lot of code, and with several searching in a script it can be very repetetive, not to mention hard to read.

Here is an example of a traditional NetSuite search:

var filters = [];
filters.push(new nlobjSearchFilter('item', null, 'anyof', item));
filters.push(new nlobjSearchFilter('location', null, 'noneof', '@NONE@'));
var columns = [];
columns.push(new nlobjSearchColumn('internalid'));
columns.push(new nlobjSearchColumn('trandate').setSort());
columns.push(new nlobjSearchColumn('location'));
var search = nlapiSearchRecord('workorder', '', filters, columns);

Using my function, the code wold be simplified to this:

var search = new Search('workorder');
search.addFilter('item', null, 'anyof', item);
search.addFilter('location', null, 'noneof', '@NONE@');
search.addColumn('internalid'));
search.addColumn('trandate',true);  // Sort on this column
search.addColumn('location');
var search = search.getResults();

The function also support saved searches. Simply add the following line:

search.useSavedSearch('custsearch123');

There is a limitation in SuiteScript so that a maximum of 1000 records can be returned by a normal search. There is a trick to bypass this, but it requires some extra coding. So I thought why not add this into the function as default? So I did.

Below is the code for the search function. I usually put it in a separate file and reference it as a library in the scripts where I want to use it. This first version does not support more advanced functionality like formulas in the filters. But for most searches this function will be usable.

/**
 * Module Description
 * 
 * Version    Date            Author           Remarks
 * 1.00       11 Nov 2016     kmartinsson
 * 1.05       27 May 2017     kmartinsson      Added support for record type in constructor
 *
 */
//***** Encapsulate search functionality *****
function Search(recordtype) {
   this.columns = [];
   this.filters = [];
   // If record type/ID is passed, no need to set it later
   if (recordtype == null || recordtype == "") {
      this.recordType = null;
   } else {
      this.recordType = recordtype;
   }
   // Set internal id of saved search to null
   this.internalId = null;
   // *** Set array of column names to return
   this.setColumns = function(columnArray) {
      for (var i = 0; i < columnArray.length; i++) { // Check if we have an array, used for joins and sorts if (columnArray[i].isArray()) { // We have an array. Now we need to figure out what it contains if (columnArray[i].length > 2) {
               // We have 3 values, must be id, join and sort
               this.addColumnJoined(columnArray[i][0], columnArray[i][1], columnArray[i][2]);
            } else {
               // We have 2 values, can be id + join or id + sort. Let's find out!
               if (typeof(columnArray[i][1]) == "boolean") {
                  // Boolean value in second parameter means sorting
                  this.addColumn(columnArray[i][0], columnArray[i][1]);
               } else {
                  // Not boolean means a join
                  this.addColumnJoined(columnArray[i][0], columnArray[i][1]);
               }
            }
         } else {
            this.addColumn(columnArray[i]);
         }
      }
   } // end function setColumns

   // *** Add column to existing array of column names
   this.addColumn = function(columnName, sorted) {
      if (sorted == undefined || sorted == null) {
         this.columns.push(new nlobjSearchColumn(columnName));
      } else {
         if (sorted) {
            this.columns.push(new nlobjSearchColumn(columnName)).setSort(true);
         } else {
            this.columns.push(new nlobjSearchColumn(columnName));
         }
      }
   } // end function addColumn

   // *** Add joined column with to existing array of column names
   this.addColumnJoined = function(columnName, joinName, sorted) {
      if (sorted == undefined || sorted == null) {
         this.columns.push(new nlobjSearchColumn(columnName, joinName));
      } else {
         if (sorted) {
            this.columns.push(new nlobjSearchColumn(columnName, joinName)).setSort(true);
         } else {
            this.columns.push(new nlobjSearchColumn(columnName, joinName));
         }
      }
   } // end function addColumnJoined

   // *** Add a filter for the search results
   this.addFilter = function(fieldId, fieldJoinId, operator, value) {
      this.filters.push(new nlobjSearchFilter(fieldId, fieldJoinId, operator, value));
   } // end function addFilter

   // *** Set the type of record to search for (default is null)
   this.setRecordType = function(recordType) {
      this.recordType = recordType;
   } // end function setRecordType

   // *** Set the saved search to use (internal id, default is null)
   this.useSavedSearch = function(internalId) {
      this.internalId = internalId;
   } // end function useSavedSearch

   // *** Return search results, supports >1000 results through nlapiCreateSearch
   this.getResults = function() {
      var results = [];
      if (this.internalId != null) {
         // If internal id of a saved search is provided, load 
         // that saved search and create a new search based on it
         var savedsearch = nlapiLoadSearch(this.recordType, this.internalId);
         // Add new filters to saved filters
         var newfilters = savedsearch.getFilters().concat(this.filters);
         // Add new columns to saved columns
         var newcolumns = savedsearch.getColumns().concat(this.columns);
         // Perform the search
         var newsearch = nlapiCreateSearch(savedsearch.getSearchType(), newfilters, newcolumns);
         // 
      } else {
         // Otherwise build the search ad-hoc and set columns and filters
         var newsearch = nlapiCreateSearch(this.recordType, this.filters, this.columns);
      }
      var resultset = newsearch.runSearch();
      // Loop through the search result set and build a result array
      // so the search can return more than 1000 records.
      var searchid = 0;
      do {
         var resultslice = resultset.getResults(searchid, searchid + 800);
         for (var rs in resultslice) {
            results.push(resultslice[rs]);
            searchid++;
         }
      } while (resultslice.length >= 800);
      return results;

   } // end function getResults

} // end class search

 

My Connect 2017 demo code

Posted on July 4, 2017 by Karl-Henry Martinsson Posted in #IBMChampion, Connect, Lotusscript, Programming, Web Development 1 Comment

The demo database from my presentation at IBM Connect 2017 is finally available.

It contains the code from The Great Code Giveaway as well as the bonus application for version management.

Don’t forget to sign the databases with an ID that has rights to run agents on the server.

Download Demo Database

 

HCL Ambassador 2020

HCL Ambassador 2020

IBM Champion 2014-2020

Stack Exchange

profile for Karl-Henry Martinsson on Stack Exchange, a network of free, community-driven Q&A sites

Notes/Domino Links

  • Planet Lotus Planet Lotus
  • IBM dW Forums IBM dW Forums
  • StackOverflow StackOverflow

Recent Posts

  • Notes and Domino v12 is here!
  • NTF Needs Your Help
  • Helpful Tools – Ytria EZ Suite (part 2)
  • Busy, busy – But wait: There is help!
  • Semantic UI – An alternative to Bootstrap?

Recent Comments

  • Lotus Script Multi-thread Message Box [SOLVED] – Wanted Solution on ProgressBar class for Lotusscript
  • Viet Nguyen on Keep up with COVID-19 though Domino!
  • Viet Nguyen on Keep up with COVID-19 though Domino!
  • Mark Sullivan on Looking for a HP calculator? Look no further!
  • Lynn He on About This Blog

My Pages

  • How to write better code in Notes

Archives

  • June 2021 (1)
  • April 2021 (2)
  • March 2021 (1)
  • August 2020 (3)
  • July 2020 (2)
  • April 2020 (2)
  • March 2020 (1)
  • December 2019 (2)
  • September 2019 (1)
  • August 2019 (2)
  • July 2019 (2)
  • June 2019 (3)
  • April 2019 (2)
  • December 2018 (1)
  • November 2018 (1)
  • October 2018 (5)
  • August 2018 (2)
  • July 2018 (3)
  • June 2018 (2)
  • May 2018 (1)
  • April 2018 (2)
  • March 2018 (1)
  • February 2018 (2)
  • January 2018 (4)
  • December 2017 (3)
  • November 2017 (2)
  • October 2017 (2)
  • September 2017 (1)
  • August 2017 (2)
  • July 2017 (6)
  • May 2017 (4)
  • February 2017 (1)
  • January 2017 (2)
  • December 2016 (2)
  • October 2016 (3)
  • September 2016 (4)
  • August 2016 (1)
  • July 2016 (2)
  • June 2016 (2)
  • May 2016 (3)
  • April 2016 (1)
  • March 2016 (4)
  • February 2016 (2)
  • January 2016 (4)
  • December 2015 (3)
  • November 2015 (2)
  • October 2015 (1)
  • September 2015 (2)
  • August 2015 (1)
  • July 2015 (5)
  • June 2015 (2)
  • April 2015 (2)
  • March 2015 (3)
  • February 2015 (2)
  • January 2015 (10)
  • December 2014 (1)
  • November 2014 (3)
  • October 2014 (3)
  • September 2014 (13)
  • August 2014 (6)
  • July 2014 (5)
  • May 2014 (3)
  • March 2014 (2)
  • January 2014 (10)
  • December 2013 (5)
  • November 2013 (2)
  • October 2013 (5)
  • September 2013 (4)
  • August 2013 (7)
  • July 2013 (3)
  • June 2013 (1)
  • May 2013 (4)
  • April 2013 (7)
  • March 2013 (8)
  • February 2013 (9)
  • January 2013 (5)
  • December 2012 (7)
  • November 2012 (13)
  • October 2012 (10)
  • September 2012 (2)
  • August 2012 (1)
  • July 2012 (1)
  • June 2012 (3)
  • May 2012 (11)
  • April 2012 (3)
  • March 2012 (2)
  • February 2012 (5)
  • January 2012 (14)
  • December 2011 (4)
  • November 2011 (7)
  • October 2011 (8)
  • August 2011 (4)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (4)
  • April 2011 (4)
  • March 2011 (7)
  • February 2011 (5)
  • January 2011 (17)
  • December 2010 (9)
  • November 2010 (21)
  • October 2010 (4)
  • September 2010 (2)
  • July 2010 (3)
  • June 2010 (2)
  • May 2010 (3)
  • April 2010 (8)
  • March 2010 (3)
  • January 2010 (5)
  • November 2009 (4)
  • October 2009 (7)
  • September 2009 (1)
  • August 2009 (7)
  • July 2009 (1)
  • June 2009 (4)
  • May 2009 (1)
  • April 2009 (1)
  • February 2009 (1)
  • January 2009 (3)
  • December 2008 (1)
  • November 2008 (1)
  • October 2008 (7)
  • September 2008 (7)
  • August 2008 (6)
  • July 2008 (5)
  • June 2008 (2)
  • May 2008 (5)
  • April 2008 (4)
  • March 2008 (11)
  • February 2008 (10)
  • January 2008 (8)

Categories

  • AppDev (9)
  • Blogging (11)
    • WordPress (5)
  • Design (5)
    • Graphics (1)
    • UI/UX (2)
  • Featured (5)
  • Financial (2)
  • Food (5)
    • Baking (3)
    • Cooking (3)
  • Generic (11)
  • History (5)
  • Hobbies (10)
    • LEGO (4)
    • Photography (4)
  • Humor (1)
  • IBM/Lotus (175)
    • #Domino2025 (14)
    • #DominoForever (8)
    • #IBMChampion (46)
    • Administration (7)
    • Cloud (7)
    • CollabSphere (8)
    • Community (47)
    • Connect (33)
    • ConnectED (12)
    • Connections (3)
    • HCL (12)
    • HCL Master (1)
    • IBM Think (1)
    • Lotusphere (46)
    • MWLUG (25)
    • Notes/Domino (97)
      • Domino 11 (7)
    • Sametime (8)
    • Verse (14)
    • Volt (2)
    • Watson (6)
  • Life (8)
  • Microsoft (7)
    • .NET (2)
    • C# (1)
    • Visual Studio (1)
  • Movies (3)
  • Old Blog Post (259)
  • Personal (23)
  • Programming (83)
    • App Modernization (11)
    • Formula (4)
    • Lotusscript (46)
    • NetSuite (4)
      • SuiteScript (3)
    • node.js (4)
    • XPages (4)
  • Reviews (9)
  • Sci-Fi (4)
  • Software (24)
    • Flight Simulator (2)
    • Games (4)
    • Open Source (2)
    • Utilities (6)
  • Technology (37)
    • Aviation (3)
    • Calculators (2)
    • Computers (6)
    • Gadgets (7)
    • Mobile Phones (7)
    • Science (3)
    • Tablets (2)
  • Travel (6)
    • Texas (2)
    • United States (1)
  • Uncategorized (15)
  • Web Development (50)
    • Frameworks (23)
      • Bootstrap (14)
    • HTML/CSS (12)
    • Javascript (32)
      • jQuery (23)

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Tracking

Creeper
MediaCreeper
  • Family Pictures
© TexasSwede 2008-2014