Saturday, May 28, 2011

Alternate more efficient way to Debug Webstore Scriptable Cart

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

Recently, I had a nice email conversation with Jason K. from NetSuite. He thought my workaround for debugging scriptable cart/checkout was very clever. It means alot coming from him. However, he actually came up with even better way of debugging scriptable cart/checkout. Jason, you are the MAN!

His method resolves the issue of eating away at script metering in my version of workaround. Using nlapiRequestURL() eats 10 governance from allowance and it causes issue during form testing. He also mentioned something very important as well. With v2011.1, NetSuite relaxed the rules on type of Sales Order form that can be used for scriptable cart/checkout. This means, you are not restricted to using External Sales Order. You can customize Standard Sales Order and use it for the scriptable cart.

Here is how you go about doing this: Thank you Jason K. for coming up with this workaround!

Step 1: Create custom sales order forms for both Invoice and CashSales from standard invoice sales order and standard cashsale sales order.
Setup > Customization > Transaction Forms
** Make sure you do NOT put anything under custom code tab for both forms!!!
After you create the two new forms, make a note of their Internal IDs. You will need them in step 2.

Step 2: Create alternate version of your scriptable cart script. Keep currently working version as your backup. You may need it.
At the top of every event functions, add following line of code:
if (nlapiGetFieldValue('customform') != '[InternalID of SO Invoice from Step 1]'
&&   nlapiGetFieldValue('customform') != 'InternalID of SO CashSale from Step 1') {
  return;
}
This ensures that script only fires for the sales order forms you are using on Webstore.
Make sure every time you want to print debugging message, you use nlapiLogExecution() call to do so.

Step 3: Create new "Client Script" file and deploy it for all Sales Order.
Creating new script file: Set > Customization > Script > New > Client Script
Don't for get to fill out all your event functions and attach any library scripts. Deploying this script for Sales order is up to your preference. I usually do "Save & Deploy".
When you are deploying your client script for sales order, make sure list of audience includes Customer Center and perhaps most obvious thing, make sure it Applies to Sales Order.

Step 4: Attach newly created Sales Order forms to your webstore
Setup > Web Site > Set up web site. 
Under the Setup Tab > Preferences section, select new invoice sales order for Scripting Template (Invoice) and new cash sale sales order for Scripting Template (Credit Card).

That's it! To view execution logs, you can to go Script or Script Deployment record and click Execution Log tab.

Hope this works out for you guys. Thank you again Jason K for this workaround!

No comments:

Post a Comment