Exporting Locations for a Customer using Acumatica API - acumatica

I'm trying to use the Acumatica Web Services API to export all Locations for a Customer. I would expect that using the Locations screen I could set a filter on the Customer ID field, which I think is LocationSummary.Customer, and that would return me all Locations for that customer. Instead, I'm always getting 0 results returned. Code is below, and I've also shown a screen shot of the Locations that exist for a test customer with ID 012349, and the debugger results showing 0 records returned.
Public Function GetAddressList(ByVal customerID As String) As String()()
Dim address As CR303010Content = m_context.CR303010GetSchema()
m_context.CR303010Clear()
Dim customerFilter As Filter = New Filter()
customerFilter.Field = address.LocationSummary.Customer
customerFilter.Condition = FilterCondition.Equals
customerFilter.Value = customerID
Dim searchfilters() As Filter = {customerFilter}
Dim searchCommands() As Command = {address.LocationSummary.Customer, address.LocationSummary.LocationID, address.GeneralInfoLocationAddress.AddressLine1, address.GeneralInfoLocationAddress.City}
Dim searchResult As String()() = m_context.CR303010Export(searchCommands, searchfilters, 0, False, False)
Return searchResult
End Function
Debugger showing searchResult array with a length of 0

I tried your example and couldn't get it to work using filters. I modified it slightly to pass the customerID in the search commands instead, and to add ServiceCommands.EveryLocationID to it to specify that we want system to loop through all locations:
Dim searchCustomer As New Value() With {.Value = customerID, .LinkedCommand = address.LocationSummary.BusinessAccount}
Dim searchCommands() As Command = {searchCustomer,
address.LocationSummary.ServiceCommands.EveryLocationID, address.LocationSummary.LocationID, address.GeneralInfoLocationAddress.AddressLine1, address.GeneralInfoLocationAddress.City}
Dim searchResult As String()() = screen.Export(searchCommands, Nothing, 0, False, False)

Related

BAPI_MATERIAL_MRP_LIST returns empty values in VBA

I use an Excel macro to get values from SAP, especially for planned orders.
Function GetOrders(ByVal ProductNumber As String)
Dim OrderList As Object: Set OrderList = SAP.Add("BAPI_MATERIAL_MRP_LIST")
Dim OrderMat As Object: Set OrderMat = OrderList.Exports("MATERIAL")
Dim OrderPlant As Object: Set OrderPlant = OrderList.Exports("PLANT")
Dim OrderTable As Object: Set OrderTable = OrderList.Tables("MRP_IND_LINES")
OrderTable.FreeTable
OrderMat = ProductNumber
OrderPlant = "XXX"
OrderList.Call
Set GetOrders = OrderTable
Set OrderMat = Nothing
Set OrderPlant = Nothing
Set OrderTable = Nothing
End Function
I changed the OrderPlant for the question.
It's working on one PC but using the same SAP account on another one we get some empty values. Specifically all the numbers > 10k are not shown.
On my PC I get something like this as a result from the MRP_IND_LINES table:
P.cons 00XXXXXXXX/XXXXXX/XXXX -21.600.000
P.cons 00XXXXXXXX/XXXXXX/XXXX -3.600.000
On another PC I the -21.600.000 is empty so it shows like this:
P.cons 00XXXXXXXX/XXXXXX/XXXX
P.cons 00XXXXXXXX/XXXXXX/XXXX -3.600.000
The disappearing field is the "REC_REQD_QTY", number 16 of the table BAPI_MRP_IND_LINES (MRP: Single Lines of MRP Elements), Data Type: "QUAN"
The only difference between the PCs is the SAP logon GUI version, 720 on mine and 750 on the other PC.
This happens only on the big numbers. The other fields in the row are downloaded correctly.
I'm not using SAP GUI scripting, but I've created the SAP Object with the row
Set SAP = CreateObject("SAP.Functions.Unicode")

Set a value from a collection to a variable

I am trying to do some debugging and I have a collection I created from several different strings. What I would like to do is go back and set another variable equal to the second item in the collection. Is this possible? See a very simplified example below:
Dim TagForms As New Collection
Dim TagForm1 As String
Dim TagForm2 As String
Dim TagForm3 As String
Dim Test As String
TagForm1 = "Cat"
TagForm2 = "Dog"
TagForm3 = "Pig"
Set TagForms = New Collection
TagForms.Add TagForm1
TagForms.Add TagForm2
TagForms.Add TagForm3
Test = TagForms(2) 'This doesn't work
Set Test = TagForms(2) 'This also doesn't work
As the variable 'Test' is a string, the last code line 'Set Test = TagForms(2)' does not work.
The correct code line is 'Test = TagForms(2)'. This code returns 'Dog'

Lotus Notes Database Search

i am trying to write a code to open VBA and do search based on the cell value in A1 (integer). i managed to write a code up to point where i can open the lotus notes and go to specific database. I tried many online codes but couldn't manage to find the code to search in that database. "Lotus.NotesSession" doesn't work the excel version i use. Could you please help me to finish this code. Code is below:
Sub macro4()
Dim uiWs As Object
Dim dbname As String
Dim serverName As String
Dim db As NotesDatabase
Dim doccol As NotesDocumentCollection
Dim varA As Integer
dbname = "***"
serverName = "***"
Set uiWs = CreateObject("Notes.NotesUIWorkSpace")
Call uiWs.OpenDatabase(serverName, dbname)
Set db = uiWs.GetDatabase(serverName, dbname) ---->where i get the error
varA.Value = Sheets("sheet1").Range("A1").Value
Set doccol = db.FTSearch(varA, Nothing, 0)
End Sub
In Notes there are two "parent"- classes to derive everything from. The NotesUIWorkspace is the class for the "frontend": It contains everything that you SEE in the client. The NotesSession is the class for the backend. NotesDatabase is a backend- class. To correctly get your database, you need to use NotesSession:
Set ses = CreateObject("Notes.NotesSession")
Set db = ses.GetDatabase(serverName, dbname)
You mixed up COM and OLE Integration. The thing you tried to use (Lotus.NotesSession) is for COM only and you need to include Notes in your project to use this.
For your example to work you need to use the OLE integration: Notes.NotesSession
Now to your "Search"- Code:
There are two different ways to search a NotesDatabase:
There is the Fulltextsearch and the "normal" search.
The Fulltextsearch just searches for your value everywhere in all documents and returns a collection. A search for "Tom" in a mailfile will find all mails / calendar entries that where:
sent by Tom
received by Tom
have the word "Tom" in subject or body or an attachment of the mail.
The syntax for FTSearch is:
Set doccol = db.FTSearch( YourSearchValue )
You can restrict the search to one certain field by using a special syntax for your search. e.G. to only search in the "From" field you could write
[From] = "YourSearchValue"
In FTSearch the "=" always means "contains"
The normal search uses a Formula (in #Formula- syntax) to search for a document. It needs the right syntax, otherwise it will not find anything. A formula to search all documents that come from "Tom" would be:
#Contains( From ; "Tom" )
The syntax for search is:
Set doccol = db.Search( YourQueryAsExampleAbove, Nothing, 0 )
With Nothing = Cutoffdate (if given only return documents created or modified after the date) and 0 = max. number of documents to return (0 = return everything).
So your example code for the could be something like:
strQuery = "FieldToSearch = " & Sheets("sheet1").Range("A1").Value
Set doccol = db.Search( strQuery, Nothing, 0 )
After calling OpenDatabase successfully, you can use
set uiDb = uiWS.CurrentDatabase
That will get a NotesUIDatabase object, and then you can use
set db= uiDb.Database
That will get you the NotesDatabase object that you need in order to call the FTSearch method.

VBA Function - Argument Not Optional

Public Function RETURN_Equipment(Optional category As String) As Collection
Dim config As classConfiguration
Set config = New classConfiguration
Dim item As classItem
Set item = New classItem
Dim myCollection As Collection
Set myCollection = New Collection
For Each config In Configurations
For Each item In config.colItems
If IsMissing(category) Then
myCollection.add item
ElseIf InStr(category, "mainframe") <> 0 And item.category = "mainframe" Then
myCollection.add item
MsgBox "Fired!"
ElseIf category = "accessory" And item.category = "accessory" Then
Else
End If
Next
Next
RETURN_Equipment = myCollection
End Function
I keep getting
Compile error:
Argument not optional
I get the error on the last line
RETURN_Equipment = myCollection
I understand the error message, its telling me I did not fill out a parameter. But I only have one parameter, and I've declared it optional. It looks like the code thinks I'm trying to call the function from the function?
What gives?
Anytime you assign an object you need to use the set keyword.
set RETURN_Equipment = myCollection
I was getting this error because I was using the wrong function name when trying to return a result from a function. I was doing this:
Function MyFuncA(arg as String)
MyFuncB = arg 'The problem is I'm using MyFuncB instead of MyFuncA
End Function
This happened because I copied a function from somewhere else and changed the name, but not the return statement. This is not the OP's problem, but I was getting the same error message.
Because you've specified the Optional Parameter as a string it will default to an empty string if you've not specified a value.
This means it can't be missing
If you'd specified it as
Public Function RETURN_Equipment(Optional category) As Collection
It would be a variant and that could be missing, although you'd also be able to mess things up by passing non string variants as the category parameter
The best course of action is probably to replace
If IsMissing(category) Then
with
If category = "" Then
And as Brad has pointed out you'll need to use Set
Set RETURN_Equipment = myCollection
For full details check this
http://msdn.microsoft.com/en-us/library/office/gg251721%28v=office.15%29.aspx

Filling BAPI import table parameter in EXCEL using VBA

I have a query for me which requires to clear. I am using excel 2003. the sheet contains 12 columns. I need to do export data from excel to SAP. Before exporting I need to check if the record is exist or not, if exist then delete and insert.
I have two BAPIs for this one is import table, which needs to be filled the parameters, after filling this table the BAPI searches for the relevant records.
The list will be displayed in a table. I need to search that table with values from excel then import one field value to excel.
I write this code but, it is not working the BAPI giving Error 0.
Public Function Import_Order() As Boolean
Dim oBAPIGetOrder As Object
Dim oBAPIVariant1 As Object
Dim oBAPIVariant2 As Object
Dim oBAPIVariant3 As Object
Dim oBAPIImpOrder As Variant
Dim oBAPIRet As Boolean
Dim oDoNothing As Variant
gBAPIPlanOrder = 0
Set oBAPIGetPlOrder = sBAPIControl.Add("PLANED_GET_DET_LIST") 'BAPI
Set oBAPIVariant1 = oBAPIGetPlOrder.exports.Item("SELECTIONCRITERIA") 'Internal table
Set oBAPIVariant2 = oBAPIGetPlOrder.Tables.Item("DETAILEDLIST") 'Table
oBAPIVariant1.Value("MATERIAL") = eMaterial
oBAPIVariant1.Value("PLANT") = ePlnPlant
lBAPIRet = oBAPIGetPlOrder.call
If lBAPIRet Then
'oBAPIImpOrder = oBAPIGetPlOrder.imports.Item("PLANNEDORDER_NUM")
a = oBAPIVariant2.Rows.Count
oBAPIImpOrder = oBAPIVariant2.Value("PLANNEDORDER_NUM")
Import_PlannedOrder = True
Else
oBAPIImpOrder = 0
Import_PlannedOrder = False
End If
End Function
Thanks in advance for any help...
please place the call function statement
lBAPIRet = oBAPIGetPlOrder.call
after directly the exports statement and before the tables and importstatements

Resources