|
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. The jQuery Javascript library is used extensively by the DbNetSuite components and is therefore also available for any custom client-side programming. 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
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
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
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
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;
}
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) |