Skip to Content
0

SAP Business One - import AlertnativeItem - error

Apr 28, 2017 at 08:45 AM

65

avatar image
Former Member

this a code :

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

try
{
if (Connect() == 0)
{
SAPbobsCOM.CompanyService oCompanyService;
SAPbobsCOM.AlternativeItemsService AltItemsService;
SAPbobsCOM.OriginalItem OriItem;
SAPbobsCOM.OriginalItemParams OriItemParams;
SAPbobsCOM.AlternativeItem AltItem;

//oCompanyService = vCmp.GetCompanyService();
oCompanyService = vCmp.GetCompanyService();

AltItemsService = (SAPbobsCOM.AlternativeItemsService)(oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.AlternativeItemsService));

OriItem = (SAPbobsCOM.OriginalItem)(AltItemsService.GetDataInterface(SAPbobsCOM.AlternativeItemsServiceDataInterfaces.aisOriginalItem));

OriItemParams = (SAPbobsCOM.OriginalItemParams)(AltItemsService.GetDataInterface(SAPbobsCOM.AlternativeItemsServiceDataInterfaces.aisOriginalItemParams));


//'Item A00003
OriItem.ItemCode = "A00003";

// add 1
OriItem.AlternativeItems.Add();
AltItem = OriItem.AlternativeItems.Item(0);
AltItem.AlternativeItemCode = "A00002";
AltItem.MatchFactor = 200;

//OriItemParams = AltItemsService.AddItem(OriItem);

// add 2
OriItem.AlternativeItems.Add();
AltItem = OriItem.AlternativeItems.Item(1);
AltItem.AlternativeItemCode = "A00001";
AltItem.MatchFactor = 400;

// add all
//OriItemParams = AltItemsService.AddItem(OriItem);
OriItemParams = AltItemsService.AddItem(OriItem);

..................................................................................

when i debug a have an error:

‡ System.Exception.Message.get returned "1). [Microsoft][SQL Server Native Client 11.0][SQL Server]Conversion failed when converting the nvarchar value 'A00003\tA00002' to data type int.\n" string

please help

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
DIEGO LOTHER Apr 28, 2017 at 12:21 PM
0

Hi Bogumil,

It seems that you have something incorrect on your store procedure transaction notification. Try to comment the customize code on your transaction notification and run your code again.

Hope it helps.

Kind Regards,

Diego Lother

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 28, 2017 at 08:58 AM
0

but i woould like to add.

there is error but 2 items was added. Why is there error ?

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 28, 2017 at 01:54 PM
0

Iit did not help :(

Show 7 Share
10 |10000 characters needed characters left characters exceeded

Hi Bogumil,

Did you comment the code in transaction notification and did not work? Or did you have some doubt about how to do this?

Kind Regards,

Diego Lother

0

Bogumil,

Your code is correct. I tested on demo database and worked fine.

Kind Regards,

Diego Lother

0
Former Member
DIEGO LOTHER

Hi Diego

It's works :)

i created new database and its ok , but i have a new problem

maybe you will be know

.....

this code create 5 lines

OriItem.ItemCode = "A00003";

// add 1
OriItem.AlternativeItems.Add();
AltItem = OriItem.AlternativeItems.Item(0);
AltItem.AlternativeItemCode = "A00002";
AltItem.MatchFactor = 200;

// add 2
OriItem.AlternativeItems.Add();
AltItem = OriItem.AlternativeItems.Item(1);
AltItem.AlternativeItemCode = "A00001";
AltItem.MatchFactor = 400;

OriItemParams = AltItemsService.AddItem(OriItem);

//// add 3
OriItem.ItemCode = "A00005";


OriItem.AlternativeItems.Add();
AltItem = OriItem.AlternativeItems.Item(2);
AltItem.AlternativeItemCode = "A00006";
AltItem.MatchFactor = 400;


//// add all
OriItemParams = AltItemsService.AddItem(OriItem);

OrigItem AltItem Match Remarks
-------------------------------------------------- -------------------------------------------------- --------------------------------------- --------------------------------------------------
A00003 A00001 400.000000 NULL
A00003 A00002 200.000000 NULL
A00005 A00001 400.000000 NULL
A00005 A00002 200.000000 NULL
A00005 A00006 400.000000 NULL

(5 row(s) affected)

but i woould like to only 3

OrigItem AltItem Match Remarks
-------------------------------------------------- -------------------------------------------------- --------------------------------------- --------------------------------------------------
A00003 A00001 400.000000 NULL
A00003 A00002 200.000000 NULL

A00005 A00006 400.000000 NULL

i don't know what can i do

B

0

Hi Bogumil,

After you call

OriItemParams = AltItemsService.AddItem(OriItem);

You should initialize your object again.

OriItem = (SAPbobsCOM.OriginalItem)(AltItemsService.GetDataInterface(SAPbobsCOM.AlternativeItemsServiceDataInterfaces.aisOriginalItem));

and then fill with new info.

Kind Regards,

Diego Lother

0
Former Member

HI Diego

[SBO_SP_TransactionNotification] is empty

This database is new and i'm writing a new solutions in Visual Studio to implement Addon to import AlternativeItems because in DTW I couldn't achieved

........................

USE [SBODemoPL]
GO
/****** Object: StoredProcedure [dbo].[SBO_SP_TransactionNotification] Script Date: 2017-04-28 15:45:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SBO_SP_TransactionNotification]

@object_type nvarchar(20), -- SBO Object Type
@transaction_type nchar(1), -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)

AS

begin

-- Return values
declare @error int -- Result (0 for no error)
declare @error_message nvarchar (200) -- Error string to be displayed
select @error = 0
select @error_message = N'Ok'

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

-- ADD YOUR CODE HERE


-- Select the return values
select @error, @error_message

end

0

Bogumil,

It is very strange. What is the version of your SAP B1? Your code worked correctly on SAP B1 9.1 PL 13.

I read that you wrote that is new database, but, maybe there is something on your SBO_SP_PostTransactionNotice.

Another test that you can try, it is do this action on SAP B1 Client and look if you will get the same error.

I insist in an error on transactions because 'A00003\tA00002' is the value that sap provide for the variable @list_of_cols_val_tab_del when try to insert your record on database. This are the primary keys of the table OALI.

Hope it helps.

Kind Regards,

Diego Lother

0
Former Member
DIEGO LOTHER

You are great, thank you :)

0