How to programmatically link a document to a job in Small Business Accounting (921524)



The information in this article applies to:

  • Microsoft Office Small Business Accounting 2006
  • Microsoft Office Small Business Accounting 2006 Software Development Kit 1.2
  • Microsoft Office Small Business Management Edition 2006

INTRODUCTION

This article contains a programming example that shows how to programmatically link a document to a job in Microsoft Small Business Accounting. Small Business Accounting lets users link certain documents to a job. You can also programmatically link a document to a job by using the Microsoft Small Business Accounting Software Development Kit (SDK).

MORE INFORMATION

The following programming example creates a new invoice in Northwind Traders. The code then retrieves an existing job and links the new invoice to the job.

Note Northwind Traders is a fictitious company that is used for demonstration in SBA.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
ISmallBusinessInstance iSbi = // initialize iSbi here

//This line specifies the customer for the transaction.
ICustomerAccount cust = (ICustomerAccount) GetAccountByName(iSbi.CustomerAccounts, "School of Fine Art");

// This line specifies the job for the transaction.
IJobAccount job = (IJobAccount) GetAccountByName(iSbi.JobAccounts, "New classroom wing");


// This code creates the invoice, sets the date, and assigns the invoice to the job.
ISalesInvoice inv = iSbi.CreateSalesInvoice(false);
inv.FinancialDateTime = DateTime.Now;
inv.JobAccount = job;

// This line adds a service item line to the invoice.

IServiceItemAccount servItem = (IServiceItemAccount) GetAccountByName(iSbi.ItemAccounts, "Plumbing labor (FF)");

// This line specifies the line item and the quantity.
IItemLine docLine = (IItemLine) inv.CreateSalesInvoiceLine(DocumentLineType.ContractItemLineType);
docLine.LineItem = servItem;
docLine.Quantity = 2;

// This line saves the invoice.
inv.Save(); 


static IAccount GetAccountByName(IBaseMasterView view, string acctName)
{
	IAccount account = null;
	DataRow row = null;

	if (view != null)
	{
		DataView dv = view.DataView;

		// This line verifies that there is a column named Name. 
		// If there is no column with this name, a runtime exception error will be received.
		if (dv.Table.Columns.Contains("Name"))
		{
			dv.RowFilter = String.Format("Name='{0}'", acctName);
		}
		// The IJobAccount table does not have a Name column. Therefore, the code will search on JobName.
		else if (dv.Table.Columns.Contains("JobName"))
		{
			dv.RowFilter = String.Format("JobName='{0}'", acctName);
		}
		
		// This line verifies that there is a column named ModifiedDateTime.  
		// If there is no column with this name, a  runtime exception error will be received.
		if (dv.Table.Columns.Contains("ModifiedDateTime"))
		{
			dv.Sort = "ModifiedDateTime DESC";
		}
    
		// If there is more than one row, the code obtains the latest row.
		if (dv.Count > 0)
		{
			row = dv[0].Row;
		}
	}

	if (row != null)
	{
		account = (IAccount) view.GetByDataRow(row);
	}

	return account;
}

Modification Type:MajorLast Reviewed:7/21/2006
Keywords:kbExpertiseAdvanced kbhowto KB921524 kbAudDeveloper