cancel
Showing results for 
Search instead for 
Did you mean: 

updating user table (type document) via api

Former Member
0 Kudos

hi!

i need to update an user table that is of type document.

that table is also used as the client table in an udo.

i have tried the following code, but that of course doesn't work as the table is not a plain table but is of document type:


  Dim objUserTable As SAPbobsCOM.UserTable
  Set objUserTable = objCom.UserTables.Item("MP_TABLE_LINE")
  If objUserTable.GetByKey(objMatrix.Columns.Item("U_MP_BEnt").Cells.Item(lngRow).Specific.Value) Then

      objUserTable.UserFields.Fields.Item("U_Qty").Value = _
      	objUserTable.UserFields.Fields.Item("U_Qty").Value - dblDiff

      If Not objUserTable.Update() <> 0 Then
          Call objApp.SetStatusBarMessage(objCom.GetLastErrorDescription())
          Call objApp.MessageBox(objCom.GetLastErrorDescription())
      Else
          objMatrix.Columns.Item("U_MP_BQty").Cells.Item(lngRow).Specific.String = _
          	objMatrix.Columns.Item("11").Cells.Item(lngRow).Specific.String
      End If
  End If
  Set objUserTable = Nothing

then i tried to use a dbdatasource which i would expect to work:


  Dim objDataSource As DBDataSource
  Set objDataSource = objForm.DataSources.DBDataSources.Item("@MP_TABLE_LINE")
  
  Dim objConditions As New SAPbouiCOM.Conditions
  Dim objCond As SAPbouiCOM.Condition
  
  <just setting up conditions here>
  
  Call objDataSource.Query(objConditions)
  Call objDataSource.SetValue("U_Qty", 0, objDataSource.GetValue("U_Qty", 0) - dblDiff)

but this only results in an error code "-7006", message:

"Item - The item is not a user defined item"

how can the update be done?

regards,

thomas

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi ,

Realy Sorry for that.

objUserTable.GetByKey(objMatrix.Columns.Item("U_MP_BEnt").Cells.Item(lngRow).Specific.Value

to get a perticular record from the UserTable u have to provide "Code" field in place of "U_MP_BEnt"

the GetBykey() works on Code field which is uniques to the record

Thanks

Ankush

Former Member
0 Kudos

thanks for your answer.

but as i wrote <i>i need to update an user table that is of type document.</i>

those tables do not have a 'Code' column.

Former Member
0 Kudos

How this will work for u

i tried this code and it work for update the data.

in place of code pls provide DocEntry

Private Sub UpdateData()

Dim oUserTable As SAPbobsCOM.UserTable

oUserTable = oCompany.UserTables.Item("tbltest")

If oUserTable.GetByKey("2") = True Then

oUserTable.UserFields.Fields.Item("U_Test1").Value = "Test1"

oUserTable.UserFields.Fields.Item("U_Test2").Value = "Test2"

If oUserTable.Update() <> 0 Then

MsgBox(oCompany.GetLastErrorDescription())

End If

End If

End Sub

Thanks,

Ankush

Former Member
0 Kudos

thanks for your answer.

but as i wrote i need to update an user table that is of type 'document'.

and to make it even more complicated (and i forgot to mention it before) i want to update the client (slave) table (which means <u>the document's lines</u>).

and those tables have composite primary keys.

Former Member
0 Kudos

Thomas,

You might try updating the form and let that flow to the dbdatasource. We should be able to update the datasource with SetValue, but it doesn't work in some situations. I am getting a similar problem with a UDF on a system form.

Bruce

Former Member
0 Kudos

Hi Thomas,

U are using UserTabel Obejct , just try to Use UserTabelMD object

i am sending to how to create the User Table,

Hope it will help to

oUTb = mobjCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)

If Not oUTb.GetByKey("SPH_FORMS") Then

oUTb.TableName = "SPH_FORMS"

oUTb.TableDescription = "Activity Forms"

oUTb.TableType = SAPbobsCOM.BoUTBTableType.bott_MasterData

If oUTb.Add <> 0 Then

mobjCompany.GetLastError(lRet, sErrMsg)

Else

oUTb = Nothing

end if

be carefull before using MD object , bcoz at a time only one MD object should be in memory else it will give to Error

Thanks

Ankush Vachher

Former Member
0 Kudos

it seems to me like you haven't taken the time to read my post.

<b>i need to update the data, not the table!</b>

Former Member
0 Kudos

Hi Thomas,

U are using UserTabel Obejct , just try to Use UserTabelMD object

i am sending to how to create the User Table,

Hope it will help to

oUTb = mobjCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)

If Not oUTb.GetByKey("SPH_FORMS") Then

oUTb.TableName = "SPH_FORMS"

oUTb.TableDescription = "Activity Forms"

oUTb.TableType = SAPbobsCOM.BoUTBTableType.bott_MasterData

If oUTb.Add <> 0 Then

mobjCompany.GetLastError(lRet, sErrMsg)

Else

oUTb = Nothing

end if

be carefull before using MD object , bcoz at a time only one MD object should be in memory else it will give to Error

Thanks

Ankush Vachher