Friday, March 12, 2021

#837 - OIC --> Netsuite & HubSpot - User Events calling OIC to sync Price changes

 Following on from the previous post and it's use case - 











Firstly, a BIG THANK YOU to my colleagues Maria and Subhani for their support here!

Back to the pattern - user event script triggered when an Inventory Item is updated.

The updates I'm interested in are those to the buy and sell prices.

This is the buy price - PURCHASE PRICE


 



This is the sell price - List Price








The HubSpot Product objects has been augmented with a field to hold the Netsuite Inventory Item Internal id. The instructions on doing this have been detailed in a previous post. I also a new custom field to the Netsuite Inventory Item - 


 




















I begin with the following OIC Integration skeleton -












Here is the REST Trigger Request payload - 













My user event leverages javascript. I first need to upload this file to Netsuite - 









I can create a script based on this file, now that it has been uploaded to Netsuite -


 









I need to apply this script to the following - 











Now to the javascript code - here a big thanks to Maria! The first part checks if the purchase costs has changed. Note the 2 contexts used - oldRecord and newRecord.

It also stores the Netsuite Internal Id and the hubSopt Product id in variables.

I consulted the Netsuite Records Browser to get the actual field names - It is available here















The next part checks for list price changes - 














The final part calls OIC - 





So let's test this out - 

Purchase Price is currently 99.00










List Prices are as follows - I am primarily interested in the USA price of 559.00














Now I change the purchase price to 89.00 and the list price to 449.00.

















I save the Inventory Item - 








I check the script log - 




















This is a great feature from Netsuite - 












I check the instance in OIC - 

















All that's left is to invoke the REST connection to HubSpot in order to update the price(s).

I test out the api call in Postman -

























I validate in HubSpot - 

























I now replicate in OIC  - 

























Activate and test - 


























Again, the caveat - the above integration does not include error handling etc.

Next step would be to use the REST adapter to update the relevant Product on HubSpot.

The above script is available for download here

No comments: