Live Chat Using Netsuite as Backend

Live Chat Using Netsuite as Backend

This time I decided to practice my skills by creating a simple live chat messaging system with Netsuite as backend and Bootstrap/jQuery as frontend.

I only used one custom record with 3 fields. Two fields (Timestamp and User) were set to default to current user/current datetime. So really the only field I had to write to was the message text.

The messages are sent via POST. I am using the jStorage jQuery library as a local DB to cache the messages. Messages are cached for 60 seconds by default.

The suitelet is being polled every 2 seconds. Every time the suitelet is polled a search runs that returns the last 20 messages created within the last 30 seconds. Clientside code checks for new entries in the db and if new entries are found the messages are displayed.


Here’s the code:


  • Carl

    Great job!

    Pretty job on the inject part, Updates:
    1. Set user and timeStamp fields during saveMessage
    2. Fixed getUpdate function to get message list
    3. Still issue on: loadListeners has issue of only display new messages, jStorage issue?


    • Thanks for your comment. On issue#3: The chat only displays new messages from the moment the user joins the room, are you trying to get the previous messages as well? If so, how far back do you want the message history?

  • Dilip DiLee

    hi guys
    im facing problem in disabling field based on the value of another field(check box)
    in suitescript2.0
    im new to netsuite

    nlapidisablefield is old one

    so any api from suitscript 2.0

  • Suganthavanan T


    Its possible to Popup when message receive.

    • Adolfo Garza

      Sure, you just need to modify the displayMessage function and add an alertbox or something.

      • Suganthavanan T

        it is possible Automatically trigger?

        • Adolfo Garza

          Sure, you just need to modify the code.

          • Suganthavanan T

            Give idea for pop up and automatic trigger(only suggestion)

  • Dilip DiLee

    Hi adolfo

    how can i know whether the employee is active ( He is logged into netsuite and using it.) By Netsuite UI i can see in employee record ISACTIVE. how can i know it through code.

    • That’s simple, just do a lookup on the employee record for the “isactive” value.

      • Dilip DiLee

        How can i know currently logged in or actively using netsuite??

        • There’s nothing I know of that will tell you that. You will have to come up with a way. For example: you could run searches to see if the user has been modifying records.

  • Dilip DiLee

    Hi adolfo
    how can i use search.create.promise()

    i was not able to understand for the doc which they have given
    can u give me one small example

  • Dilip DiLee

    Cannot read property ‘0’ of undefined.

    var objRecord = currentRecord.get();

    I’m getting an Error “Cannot read property ‘0’ of undefined.” when i make use of N/currentRecord in my custom module.
    i tried to set a sublist value in Suitelet using the following code.
    where “rows” is JSON array value

    for(var j=0;j<rows.length;j++)
    var objRecord = currentRecord.get();

    sublistId: '_results_sublist'

    sublistId: '_results_sublist',
    fieldId: '_dp_tranid',


    sublistId: '_results_sublist'

  • Hi adolfo,

    why you have not made use of Cache module instead of JStorage

    • I am using jStorage for clientside caching wereas the Cache module is for serverside caching. Besides, the cache module didn’t come out after I wrote this article.

  • Alok Binwal

    Hi Adolfo I am trying to update the Journal entry line using SuiteTalk api but having an issue regarding to the permission that is –
    You do not have permissions to set a value for element line.line due to one of the following reasons:
    1) The field is read-only;
    2) An associated feature is disabled;
    3) The field is available either when a record is created or updated, but not in both cases.
    I found an alternate solution to fix this issue but that is a kind of a patch which involved a risk for business point of view.
    I am new in NetSuite and I looked into the Suitelet, so is it possible to update the existing record using suitlet. If you have any clue about it please share with me.

    • hmmm… seems like you are trying to update the field “line” which is immutable that’s why you are getting that error. Try setting only things you can change like the account and amounts.

      • Alok Binwal

        Hi Adolfo thanks for your reply, I tried to change the account and other fields but having the same issue, and same approach is being used to update the expanse report custom fields where it works fine but failed to update the JE custom fields. When I mentioned line specified true for existing record it creates the new one and throw the error where line specified is set to false for existing record. And why “line” is immutable only for the JE ?

        • You can’t change the line because “line” is the index. As to why you are running into that issue, I would recommend checking the record using the UI and see if you can actually edit the record. If you don’t see the edit button then the record is probably not editable anymore because it’s already posted or other non-technical reason. If you want to take the Suitescript route I can tell you I just verified and I was able to change the memo on one of the lines of an editable journal entry. I’d create a Suitelet/Restlet to run the logic and call it within the app. Still, keep powering through that Suitetalk issue, I am pretty sure you are close to getting around it. PD: Here’s a quick snippet on how I did it in SS 1.0:

  • Mangesh Nidhonkar

    hi Adolfo, I’m new in Netsuite Suitescript 2.0. I have one question. I have suitelet form, on that form I have create 2 text field and one button (i.e. Submit). After putting values on two field’s and click on submit button then form data will be showed on Netsuite. How we can do that.

    • You can set the Suitelet to do something whenever it receives a POST request. The POST request will be triggered by the submit button.