How NetSuite Schedule Scripts Help Notify Customers on Upcoming Invoices Due

How NetSuite Schedule Scripts Help Notify Customers on Upcoming Invoices Due

NetSuite

TMnow | 27 May 2023

Introduction

  • It is a common practice to intimate customers before the invoice due date in any business.
  • It’s ok to pull all invoices by record and inform customers individually manually, but if a business has a ton of invoices manual pulling of records can be an uphill battle.
  • To address this challenge we will be using a Schedule Script and automating the process of notifying the customers.

Why is a Schedule Script necessary?

  • With the aid of a Scheduled Script and Saved Search, we can notify customers within a fraction of a second.

For this Customization we use

Schedule Script

  1. Schedule Scripts are server-side scripts. When we want to schedule a functionality or task, we use Schedule Scripts executed with SuiteCloud processors to process vast amounts of data that can work on a recurring basis.
  2. In order to submit scripts for processing at a later time or on a recurrent basis, you can deploy Scheduled Scripts. They consist of any planned activities that the shop may carry out in the background.

Benefits of using Schedule Script in NetSuite:

  • Scheduled scripts are used most frequently in NetSuite, along with User Event, Client, and Mass Update scripts.
  • Scheduled scripts have the advantage of being able to run in the background and perform tasks on a greater scale than some of the other scripts.
  • A scheduled script can handle whatever tasks you need to run on all transactions produced in a day or a week, or over a time range.

Sample Use Case:

Here is an example of Reminding customers of the impending invoice due date prior to 5,10,15.

Implementation Process:

  • We are creating a saved search to get details of the open invoice and whose due dates are 5,10,15 days.

var transactionSearchObj = search.create(

    		   type: "transaction",

    		   filters:

    		   [

      [["status","anyof","CustInvc:A"],"AND",["mainline","is","T"]], 

      "AND", 

      [[["formulanumeric: ROUND({duedate}-{today})","equalto","5",]],"OR",

[["formulanumeric:ROUND({duedate}-{today})","equalto","10"]],"OR",

[["formulanumeric: ROUND({duedate}-{today})","equalto","15"]]]

   ],

    columns:

    [

    search.createColumn({name: "internalid", label: "Internal ID"}),

    search.createColumn({name: "custcol_2663_companyname",

label: "Company Name"}),

    search.createColumn({name: "custbody22",

label: "Created __by"}),

    search.createColumn({name: "supervisor",

    		                    join: "CUSTBODY22",

    		                    label: "Supervisor"

    		                    }),

    search.createColumn({name: "tranid", 

label: "Document Number"}),

    search.createColumn({name: "internalid",

    		                    join: "customerMain",

    		                    label: "Internal ID"

    		                    }),

    search.createColumn({name: "formulanumeric",

    		                    formula: "ROUND({today}-{duedate})",

label: "today-duedate"

    		                    }),

   search.createColumn({name: "email",

join: "customerMain",

    		         	          label: "Email"

    		      })

    		   ]

    		});


{        

  • From the above code, we are getting details of open invoices which are having due dates prior to 5,10,15.

Obj_key=receiverEmail

 Obj_values={				 

                     "internalid":recordid,

                   "createdby":createdby,

                     "Supervisor":supervisor,

                     "link":link,

                     "Doc_Num":document number,

                     "days overdue":days_due,

                     "Customer_internalid":customer

                 };

				 

if (Obj_map[Obj_key] == undefined) {

					Obj_map[Obj_key] = [Obj_values]

}

	              else {

					Obj_map[Obj_key].push(Obj_values);

	              	 };        

  • With the help of the above logic, we are able to create an object with customer mail as a key.

Var customer=Object.values(Obj_map);

 var to_email=Object.keys(Obj_map);

var table='';

          table+='<html><style>table, th, td {border:1px solid black,class="sortable";}';

      	table +='</style>';

      	table +='<body>';




      	table +='<h2>Invoices</h2>';




    	table +='<table style="width:100%">';

    	table +='<tr>';

    	table +='<th>Document Number</th>';

         table +='<th>Days Over Due</th>';

    	table +='<th>link</th>';

    	

    	table +='</tr>';

          for(i=0;i<cstomer.length;i++)

            {

        	   log.debug('why are you looping IIIII'+i);

            //  log.debug('inside for values',cstomer[i]);

              var x=cstomer[i];

              

            var customer_internalid=x.Customer_internalid;

           

            var documentnumber=x.Doc_Num;

            var link=x.link;

              var created=x.createdby;

             var customermail=x.customeremail;

             var overduedays=x.daysoverdue;

              var int_id=x.internalid;        

  • Below We are attaching a table if a customer has multiple invoices which are due in 5,10,15 days with the invoice document number and invoice link and days remaining for the due date as table columns.
  • We are scheduling this script every day so that customers will be notified without any employee intervention.

  table +='<tr>'

        	table +='<td>'+documentnumber+'</td>';

        	table +='<td>'+overduedays+'</td>';

        	table +='<td>'+link+'</td>';

        	table +='</tr>';

           

            }

          table +='</table>';

      	table +='</body>';

      	table +='</html>';	

      	var emailBody = "These invoices Will be  overdue in   #"+table;

          

var author=A/P_Analist;

        	email.send({

    			author:author,

    			recipients:to_email,

    			subject: emailSubject,

    			body: emailBody,

          relatedRecords:{entityId:author,

                          entityId:customer_internalid

                         }

    		});;        

  • With the help of email send API in NetSuite we are sending mails to customers in NetSuite.

FAQ

  1. Can we have a track of emails that we send to customers? Yes, we have a track for sending out emails to the customer. All sent email data will be stored under the communication tab in the customer record.
  2. How Frequently can we run the Scheduled Script? Scheduled Scripts can be set to run as frequently as every 15 minutes or as infrequently as once a year or once a month, or once a day. 
  3. Can we attach files with this customization? Yes, we can attach files with this customization not more than 10 MB.

More Questions?

Visit: www.techmantranow.com 

--------------------------------------------------------------------------------

Need help selecting the right enterprise products & solutions for your business? Connect with TechMantra Now's Cloud ERP Software experts!

To view or add a comment, sign in

More articles by TechMantra Now

Others also viewed

Explore content categories