cancel
Showing results for 
Search instead for 
Did you mean: 

Creating A/R invoice draft

Former Member
0 Kudos

Hi all,

I got this working for creating A/P invoice drafts but now I am having difficulty creating a A/ R Invoice draft. I keep getting an error message.

"ClassFactory cannot supply requested class"

Here is my code.


if (vCompany.Connect() == 0)
		{
		
			SAPbobsCOM.Documents oInvDraft = new SAPbobsCOM.Documents();
			oInvDraft = (SAPbobsCOM.Documents)vCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);

			oInvDraft.DocObjectCode = SAPbobsCOM.BoObjectTypes.oInvoices;
			oInvDraft.DocType = BoDocumentTypes.dDocument_Items;
			oInvDraft.CardCode = sSAPCardCode;
			oInvDraft.NumAtCard = sRefNo;
			oInvDraft.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO;
			oInvDraft.PaymentGroupCode = -1;
			oInvDraft.DocDate = DateTime.Now;
			oInvDraft.DocTotal = FormTotal;
oInvDraft.Lines.AccountCode = rReaderLI.GetString(iProdID);
				oInvDraft.Lines.Quantity = 1;
				oInvDraft.Lines.TaxCode = "exempt";
				oInvDraft.Lines.Price = double.Parse(rReaderLI.GetString(iSalePrice));
				
				oInvDraft.Lines.ItemDescription = rReaderLI.GetString(iProd);
				oInvDraft.Lines.Add();
			
			}
			RetVal = oInvDraft.Add();

}

Anyone have any ideas?

Thanks, Rhonda

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi, Rhonda!

I suppose the reason is in incorrect adding new lines in a document. The first line doesn't have to be added using "Add" method.

It's the sample from DI help:

'----


vInvoice.Lines.ItemCode = "A00023"

vInvoice.Lines.ItemDescription = "Banana"

vInvoice.Lines.PriceAfterVAT = 2.36

vInvoice.Lines.Quantity = 50

vInvoice.Lines.Currency = "Eur"

vInvoice.Lines.DiscountPercent = 10

'Invoice Lines - Set values to the second line

vInvoice.Lines.Add

vInvoice.Lines.ItemCode = " A00033"

vInvoice.Lines.ItemDescription = "Orange"

vInvoice.Lines.PriceAfterVAT = 118

vInvoice.Lines.Quantity = 1

vInvoice.Lines.Currency = "Eur"

vInvoice.Lines.DiscountPercent = 10

'----


Just use the condition to determine whether it is the 1st line or not...

HTH,

Alexey

Former Member
0 Kudos

Nope. Still getting the same error.

ClassFactory cannot supply requested class

What's weird is the code works when creating an A/P invoice. So if I change

oInvDraft.DocObjectCode = SAPbobsCOM.BoObjectTypes.oInvoices;

to

oInvDraft.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices;

it works.

I think the error message is odd.

Rhonda

Former Member
0 Kudos

Rhonda, in this part:

SAPbobsCOM.Documents oInvDraft = new SAPbobsCOM.Documents();

oInvDraft = (SAPbobsCOM.Documents)vCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);

you initialize oInvDraft object, but you don't have to use <b>new</b> operator to declare a "Documents" object.

Method <b>GetBusinessObject</b> does this.

I've faced the same error in this part.

Have a try like that:

SAPbobsCOM.Documents oInvDraft;

oInvDraft = (SAPbobsCOM.Documents)vCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);

But when trying to Add a Draft, you can get new errors, because of incomplete declaring Document properties... (For example, "2028" error i've got, because i didn't define oInvDraft.Series property)...

Regards,

Alexey

Former Member
0 Kudos

Actually I didn't realize it because the connection was working on another application I didn't consider it could be that but it's actually happening here.


SAPbobsCOM.Company vCompany = new SAPbobsCOM.CompanyClass();
	string sDB = "testSCNA";
	vCompany.Server = "SERVER";
	vCompany.CompanyDB = sDB;
	vCompany.UserName = "Me";
	vCompany.Password = "12345";
	vCompany.DbUserName = "user";
	vCompany.DbPassword = "password";

if(!vCompany.Connected) {
		if(vCompany.Connect() != 0) {
//show error code
		}
		else {
			//I removed the invoice create.
		}


The difference is this app is written in C# and the other one was VB.net. Everything else is the same.

Rhonda

Former Member
0 Kudos

Rhonda, try to define vCompany.LicenseServer and vCompany.language (For example, vCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;)

Aleksey.

Former Member
0 Kudos

That didn't seem to help either.

Rhonda

Former Member
0 Kudos

Well I now am able to add Invoice drafts (thanks for everyone's suggestions) but I have another question that is driving me crazy. (Why is everything so difficult? I almost feel like SAP wants to keep us in the dark.)

Anyway, the line items include the following:

ItemNo

Item Detail

Free Text

Begin Date

End Date

Quantity

Price after discount

Taxcode

Total

GL Account

How the heck do I add Item Detail, Begin Date and End Date? I'm guessing that Item Detail is some sort of lookup based on the item code.

Some sample code would be most helpful.

Thanks,

Rhonda