Client-side programming

Top  Previous  Next

DbNetSuite places an emphasis on client-side programming in JavaScript which makes it easier to interact with the user via the client-interface. In additon to the client-side controls DbNetSuite also includes the following helper libraries.

jQuery

The jQuery Javascript library is used extensively by the DbNetSuite components and is therefore also available for any custom client-side programming.

DbNetLink.Util

This library makes available the following helper functions.

DbNetLink.Util.dateToString(dateValue, format)

Method to convert a string into a Javascript date object using the supplied format argument. If not supplied the format string will default to the short date pattern for the region.

Arguments

dateValue

date

A javascript date object

format (optional)

string

The format for the converted date. See Date Format Specifiers

Returns

A formatted date string.

Example

	function setDefaultHireDate(control)
	{
		control.getInputControl("HireDate").val( DbNetLink.Util.dateToString( new Date()) );
	}

DbNetLink.Util.loadCombo(combo, items, addEmptyOption, emptyOptionText)

Client-side method to populate a drop-down list element

Arguments

combo

object

Reference to the select element

items

array of objects

Array of objects with each object having a text and value property

addEmptyOption

boolean

Adds an extra empty option (optional)

emptyOptionText

string

Text for empty option

Run Sample

DbNetLink.Util.stringToDate(dateString, format)

Method to convert a Javascript date object to a string using the supplied format argument. If not supplied the format string will default to the short date pattern for the region.

Arguments

dateString

string

A date string

format (optional)

string

The format for the converted date. See Date Format Specifiers

Returns

A javascript date object

Example

	function validateForm(control, args)
	{
     	    var startDate = DbNetLink.Util.stringToDate( control.getInputControl("StartDate").val() )              
     	    var endDate = DbNetLink.Util.stringToDate( control.getInputControl("EndDate").val() )              
	
	    if (startDate.valueOf() >=  endDate.valueOf())
            {
               args.cancel = true;
               args.message = "Start date cannot be after end date");
            }
	       
	}

DbNetLink.Util.sizeWindowToContent()

Sizes the browser window to the content.

Arguments

None

Returns

Void

Example

jQuery.(document).ready( function(){ DbNetLink.Util.sizeWindowToContent()})

 

DbNetLink.Util.webMethod(method, callback, data, url)

Method to call a server-side Web Method.

Arguments

method

string

The name of the server-side web method

callback

function

Client-side method to be called on successful invocation of the method

data

object

Object with properties that correspond to the web method parameters

url

url

Web method url. Optional. If not supplied the current page url is used.

 

Example

////////////////////////////////////////////////////////////
function sendMessage(companyName, action)
////////////////////////////////////////////////////////////
{
	var data = {"CompanyName" : companyName, "Action" : action}
	DbNetLink.Util.webMethod("SendMessage", window.messageSent, data);
}
////////////////////////////////////////////////////////////
function messageSent(message)
////////////////////////////////////////////////////////////
{
	alert(message);
}
[WebMethod]
///////////////////////////////////////////////////////////////
public static string SendMessage(string CompanyName, string Action)
///////////////////////////////////////////////////////////////
{
	System.Net.Mail.MailMessage Msg = new System.Net.Mail.MailMessage();
	Msg.From = new System.Net.Mail.MailAddress("sender@domain.com");
	Msg.To.Add(new System.Net.Mail.MailAddress("recipient@domain.com"));
	Msg.Subject = "Supplier " + CompanyName;
	Msg.Body = "Supplier " + CompanyName + " " + Action + " at :" + System.DateTime.Now.ToString();
	string Message = "";

	System.Net.Mail.SmtpClient Smtp = new System.Net.Mail.SmtpClient("localhost");

	try
	{
		Smtp.Send(Msg);
		Message = "Notification sent";
	}
	catch(Exception Ex)
	{
		Message = "Notification Error ==> " + Ex.Message;
	}

	return Message;

}

Run Sample

Date Format Specifiers

The format can be combinations of the following:

   * d - day of month (no leading zero)

   * dd - day of month (two digit)

   * o - day of the year (no leading zeros)

   * oo - day of the year (three digit)

   * D - day name short

   * DD - day name long

   * m - month of year (no leading zero)

   * mm - month of year (two digit)

   * M - month name short

   * MM - month name long

   * y - year (two digit)

   * yy - year (four digit)

   * @ - Unix timestamp (ms since 01/01/1970)

   * '...' - literal text

   * '' - single quote

   * anything else - literal text

 

There are also a number of predefined standard date formats available from $.datepicker:

 

   * ATOM - 'yy-mm-dd' (Same as RFC 3339/ISO 8601)

   * COOKIE - 'D, dd M yy'

   * ISO_8601 - 'yy-mm-dd'

   * RFC_822 - 'D, d M y' (See RFC 822)

   * RFC_850 - 'DD, dd-M-y' (See RFC 850)

   * RFC_1036 - 'D, d M y' (See RFC 1036)

   * RFC_1123 - 'D, d M yy' (See RFC 1123)

   * RFC_2822 - 'D, d M yy' (See RFC 2822)

   * RSS - 'D, d M y' (Same as RFC 822)

   * TIMESTAMP - '@'

   * W3C - 'yy-mm-dd' (Same as ISO 8601)