trigger call to external webservice on record change in netsuite

Let’s say I want to add, change, or delete a PO line in NetSuite, and I need another system to know when I do that. How do I go about doing it?

I am using a PO line as an example only, but in theory I am looking for a programming pattern that could be applied to, for instance, item updates, or sales order changes.

I am thinking it has something to do with SuiteScript, and specifically the user events, but I am little unclear on it on HOW to do it. I am not talking about the communication with the webservice – that is actually the easiest part. I am talking about what to put into the SuiteScript code. My current working there is that it will be something like this (this is not perfect JavaScript, treat it more like pseudo-code):

function main ()
{
   return {
      afterSubmit: myAfterSubmit
      beforeSubmit: myBeforeSubmit
   }
}

function myBeforeSubmit(context)
{
    if (context.type == context.UserEventType.DELETE)
    {
        // Talk to other webservice, telling other system to delete record
    }
}

function myAfterSubmit(context)
{
    if (context.type == context.UserEventType.CREATE )
    {
        // Talk to other webservice, telling other system to add record
    }
    else if (context.type !== context.UserEventType.DELETE )
    {
        /* Talk to other webservice, telling other system to update record
         * This will be approve, cancel, reject, pack, ship, and edit, will probably
         * need to ignore some other UserEventType's, or just handle certain event types.
         */
    }
}

Am I at least heading in generally the correct direction. What especially confuses me from everything I have seen online is the “Delete” event.

This post is quite close, but doesn’t really give more full fledged examples, examples that show the general workflow. Also, I found this post, but it discussing using events when other systems are making an external API call to Netsuite.

Since I am new to this. there is obviously more I need to learn, but I just want to know if I am heading in close to the correct direction. Some of this I got from the documentation here, but this documentation doesn’t really address what events can and should be handled in each “submit” function.

  1. Use afterSubmit rather than beforeSubmit. If you use beforeSubmit, other scripts could change the record before it’s committed to the database.
  2. The pattern you’re using for your functions looks fine.
  3. The pattern for your overall script does not look correct to me. NetSuite expects an AMD module as your script and it should have a pattern broadly like the following:
/**
 * @NScriptType UserEventScript
 * @NApiVersion 2.1
 *
 */

define(["N/https"], function (https) {

    function beforeLoad(context) {
        ...
    }
    function beforeSubmit(context) {
        ...
    }
    function afterSubmit(context) {
        ...
    }
    return {
        beforeLoad: beforeLoad,
        beforeSubmit: beforeSubmit,
        afterSubmit: afterSubmit
    }
});

Note the mandatory JSDoc tags (@NScriptType and @ApiVersion) at the start of the file, the AMD module inclusion on the first line of the define call, and the return statement which passes the functions from the script as values for keys which match what NetSuite expects from this script type.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật