Saturday, May 14, 2011

How to debug Netsuite Webstore Scriptable Cart

We've MOVED!!!! www.codeboxllc.com/ksc


Notice:
Blogspot had issues with their server and post I originally wrote got deleted. I do apologize for missing link:

Important Update on this Post: 5/17/2011:
nlapiRequestURL() eats up API Governance meter by 10 points. Testing on External Form, if you have this turned on, you only have 1000 limit. On Webstore, you seem to have 2147483647. Don't ask me where that number came from.

So, Here I go again. How DO you debug scriptable cart executing on webstore? The script itself is attached to the External Sales Order form you create which implies is client level script. You can't use Firebug to step through it either.So how do you debug when your script is not returning the results you want?

I began using this workaround and it has helped me alot.
Workaround: Create Suitelet (Available without Login) to track printing of debug messages and call it using nlapiRequestURL() from your scriptable cart script.

Write Suitelet Script: Save as "sl_writelog.js" and push out to Netsuite 
** Please note, for simplicity, I've written my script to use GET event.
function slExecLog(request, response){
  if (request.getMethod() == 'GET') {
    var log = filterUserInput(request.getParameter('log'));
    var title=filterUserInput(request.getParameter('title'));
    writeLog('DEBUG',title,log);
    response.write('called back');
  }
}
Deploy your script:
  1. Login to Netsuite and go to Setup > Customization > Scripts > Click New
  2. Select Suitelet as script type
  3. Provide Name and ID for this script.
  4. Under Scripts tab, select "sl_writelog.js" for Script File and "slExecLog" as Function
  5. Select "Save and Deploy" option.
  6. Provide Name and ID for this script deployment
  7. Check "Available Without Login" 
  8. Select GET Request as Event Type.
    If you choose to use Post, you should change your script to check for POST and also select POST Request as Event Type
  9. Under Audience tab, select "All Roles"
  10. Save
Once you've deployed your script, copy the External URL for this deployment. According to NetSuite documentation, nlapiRequestURL() does NOT send User Session information. 

Link to your Suitelet from Scriptable cart script:
Open your scriptable cart script and create a function which will call your suitelet. This is how I did it:
Please note that anything enclosed in [ and ] is to be replaced by your code including the brackets.
function wslog(_txt) {
  if (!_txt) {
    return;
  }
  var loginUrl = '[External URL for your Suitelet]&title=[Value of title]&log='+_txt;
  if (wsdebug) {
    nlapiRequestURL(loginUrl, null, null);
    return;
  }else{
    alert(_txt);
  }
}
You will notice above that I check for wsdebug value. This is global boolean value I created so that I can turn on/off calling of my debug suitelet.
When I'm testing on the form, I set this value to false so that I can see the alert messages. Testing/deployment on webstore, I set this value to true.
Check your debug messages:
Once everything is doen, go to your Webstore and add items to your cart so that your scriptable cart script will fire.
To check the log messages, open your Suitelet script record and click on Execution Log.


No comments:

Post a Comment