is there a way to query IEmployeePayrollInfo with QuickBooks SDK? - vb.net

I am starting to work with the QuickBooks SDK, and so far I am able to query Employees no problem, like so:
_sessionManager.OpenConnection("", "<software>")
_sessionManager.BeginSession("", ENOpenMode.omDontCare)
Dim requestSet As IMsgSetRequest = GetLatestMsgSetRequest(_sessionManager)
' Initialize the message set request object
requestSet.Attributes.OnError = ENRqOnError.roeStop
Dim empQuery As IEmployeeQuery = requestSet.AppendEmployeeQueryRq()
' Do the request and get the response message set object
Dim responseSet As IMsgSetResponse = _sessionManager.DoRequests(requestSet)
Dim response As IResponse = responseSet.ResponseList.GetAt(0)
Dim empRetList As IEmployeeRetList = response.Detail
....
_sessionManager.EndSession()
_sessionManager.CloseConnection()
Which will give me a list of employees which I can iterate through. This works well for the basic employee data, such as name, date of birth, etc. but there is a EmployeePayrollInfo property that does not seem to be returned with the IEmployeeQuery.
I see that there is an interface IEmployeePayrollInfo but I have not as yet been able to figure out if there is a way to query it. I see that there are report related payroll info queries, but I am trying to query the EmployeePayrollInfo directly, to retrieve the vacation information. Is this something that can be done with QBFC?
EDIT
I was able to get this working, see accepted answer below.

Open Quickbooks.
Go to the Edit menu and click Preferences.
In the Preferences window, click Integrated Applications in the list on the left.
Click the Company Preferences tab.
Select the application with which you are connecting to QuickBooks.
Click Properties.
Check "Allow this application to access Social Security Numbers, customer credit card information, and other personal data"
The employee data should now include EmployeePayrollInfo. Please comment if this does not work.

For anyone searching for the same functionality, the only information I was able to find seems to indicate that Intuit has specifically excluded this functionality from the QuickBooks SDK for security reasons. What we ended up doing to solve our problem is create a custom report in QuickBooks that included all of the information that we needed, exported it as a CSV file, and then import it accordingly in our software. Same end result, but a couple more steps than we were originally hoping for. Hopefully Intuit will change their mind about excluding this from the SDK.
UPDATE
I have finally been able to query the EmployeePayrollInfo, what was needed was adding "EmployeePayrollInfo" to the query itself like so:
empQuery.IncludeRetElementList.Add("EmployeePayrollInfo")
So now the code looks like this:
Dim sessionManager As New QBSessionManager
sessionManager.OpenConnection2("", "<software>", ENConnectionType.ctLocalQBD)
sessionManager.BeginSession("", ENOpenMode.omDontCare)
Dim requestSet As IMsgSetRequest = sessionManager.CreateMsgSetRequest("US", 12, 0)
requestSet.Attributes.OnError = ENRqOnError.roeStop
Dim empQuery As IEmployeeQuery = requestSet.AppendEmployeeQueryRq()
empQuery.IncludeRetElementList.Add("EmployeePayrollInfo") ' this line did the trick!
Dim responseSet As IMsgSetResponse = sessionManager.DoRequests(requestSet)
Dim response As IResponse = responseSet.ResponseList.GetAt(0)
Dim empRetList As IEmployeeRetList = response.Detail
If empRetList.Count > 0 Then
For i As Integer = 0 To empRetList.Count - 1
Dim emp As IEmployeeRet = empRetList.GetAt(i)
If emp IsNot Nothing Then
' do something with the queried data
End If
Next
End If
sessionManager.EndSession()
sessionManager.CloseConnection()

Related

Can I use VBA in Access to determine if a user has multiple instances of a database open?

I am looking for a way to determine if a user current has multiple instances of an Access database open on their machine. The purpose of this check would be to ensure better session handling.
It is perfectly fine for a user to open multiple instances. There are some elements of our work where this is a necessity, to browse existing records while entering a new one.
I came across this old forum post where a function is given to output a list of the currently open databases in the Workspace. I thought I may be able to adapt this to determine if the same database is open more than once on their machine. However, in testing the function (removing the part that opens a separate database), it always outputs the name of our database twice, regardless of whether I have just one instance open, or two or three.
Here's the adapted code I am using:
Public Sub listDBs()
Dim wrkCurrentWorkSpace As Workspace
Dim i As Integer
Dim strDatabases As String
Set wrkCurrentWorkSpace = DBEngine.Workspaces(0)
For i = 0 To wrkCurrentWorkSpace.Databases.Count - 1
If (i = 0) Then
strDatabases = wrkCurrentWorkSpace.Databases(i).Name
Else
strDatabases = strDatabases & Chr$(13) & Chr$(10) & wrkCurrentWorkSpace.Databases(i).Name
End If
Next
MsgBox strDatabases
Set wrkCurrentWorkSpace = Nothing
End Sub
Am I doing something wrong here?

How can I discover an "object access flag" that is apparently needed when deleting a Quickbooks invoice data entension using QBSDK

I am using the QuickBooks QBFC12 SDK, and specifically, I am attempting to delete a "data extension" on an invoice in QB.
Some of the time the following VB.NET code will work, but many times it doesn't:
Dim objRequest As IMsgSetRequest
Dim objDatExtAdder As IDataExtAdd
Dim objResponse As IMsgSetResponse
Dim objOurResponse As IResponse
Dim objInvoiceQuery As IInvoiceQuery
Dim objInvoiceRetList As IInvoiceRetList
Dim objInvoiceRet As IInvoiceRet
Dim szInvoiceTxnID As String = ""
Dim objDataExtDel As IDataExtDel
' Check to see if the invoice is already on file.
objInvoiceQuery = objRequest.AppendInvoiceQueryRq
objInvoiceQuery.ORInvoiceQuery.InvoiceFilter.MaxReturned.SetValue(1)
objInvoiceQuery.IncludeLineItems.SetValue(True)
objInvoiceQuery.IncludeLinkedTxns.SetValue(True)
objInvoiceQuery.ORInvoiceQuery.InvoiceFilter.ORRefNumberFilter.RefNumberFilter.MatchCriterion.SetValue(ENMatchCriterion.mcEndsWith)
objInvoiceQuery.ORInvoiceQuery.InvoiceFilter.ORRefNumberFilter.RefNumberFilter.RefNumber.SetValue(szQBInvoiceNumber)
objResponse = objSessionManager.DoRequests(objRequest)
objOurResponse = objResponse.ResponseList.GetAt(0)
If objOurResponse.StatusCode = 0 Then
' Lock onto the invoice.
objInvoiceRetList = objOurResponse.Detail
If objInvoiceRetList.Count > 0 Then
' The invoice already exists.
objInvoiceRet = objInvoiceRetList.GetAt(0)
szInvoiceTxnID = objInvoiceRet.TxnID.GetValue
End If
End If
objRequest.ClearRequests()
' Remove any previous value.
objRequest = objSessionManager.CreateMsgSetRequest("US", 11, 0)
objRequest.Attributes.OnError = ENRqOnError.roeStop
objDataExtDel = objRequest.AppendDataExtDelRq()
objDataExtDel.OwnerID.SetValue("0")
objDataExtDel.ORListTxn.TxnDataExt.TxnDataExtType.SetValue(ENTxnDataExtType.tdetInvoice)
objDataExtDel.ORListTxn.TxnDataExt.TxnID.SetValue(szInvoiceTxnID)
objDataExtDel.DataExtName.SetValue(szDataExtensionName)
objResponse = objSessionManager.DoRequests(objRequest)
objOurResponse = objResponse.ResponseList.GetAt(0)
If objOurResponse.StatusCode = 0 Then
Debug.Print("Worked")
Else
Debug.Print("Didn't work")
End If
On the occasions where it reports "Didn't Work," objourresponse.StatusMessage returns:
The necessary QuickBooks object access flag was not set in the attribute definition for an attribute. QuickBooks error message: Unknown Error
I have tried to understand what the "Object Access Flag" is and where it can be found, and I have searched on Google and the Intuit developer's site for more information, but I can't find anything.
Can someone help with understanding what this is, how I can get past this issue, and how I can consistently delete this data extension whenever necessary?
After a LOT of trial and error, I believe I have struck on a solution.
The particular extension was part of a drop-down selector that I have displayed on the invoice. Some of the valid values are "Printed" or "Shipped". Formerly, when I went to change the value in the extension, I was first deleting the extension using AppendDataExtDelRq, then adding it back in with the new value using AppendDataExtAddRq.
I was able to get the value to change if, instead of using the delete/add combination, I used AppendDataExtModRq and simply changed the value.
I still think there is a bug in the SDK like #InteXX suspects, but I also noticed that IF I set the extension to a pre-defined value in the drop-down, then all is good. BUT, if I try to set the extension to a value that isn't pre-defined in QB for that extension/drop-down, then I get the exact same error:
The necessary QuickBooks object access flag was not set in the attribute definition for an attribute. QuickBooks error message: Unknown Error
So the upshot is that it is working now by using the MOD and not the DELETE/ADD approach, but make sure you set the value to a pre-defined value.

CAML query not retrieving all fields using vb.net VS2019 and Sharepoint online

I was asked to write an app at work that grabs an Employee list from our Sharepoint online site for eventual auto updating. The part I am stuck on is retrieving all of the fields of my employee list.
I would think that my query would simply bring back all of the fields that I see on my sharepoint list. But I admit that at this point that I do not have the best understanding of CAML.
So, I start to loop through each item in my Allitems object to create a datarow for each row of info so I can have a nice little data-table to display to the user. When the line of code runs to find item.("First Name") , I get the message that it is not in the list and that I may need to explicitly query it. Same with all of the other fields with a space. My AllItems object is bringing back all columns with the names that do not have a space (ie. Department, Title, Location, Email) which is strange to me.
Apparently, I do not understand Sharepoint enough and what the fields are called with a space.
I also see some C# examples with another method for the query object : query.ViewFields . I do not have this option for my query object. Also, can someone recommend another Sharepoint imports that would be beneficial here besides the ones that I am using?
Any help and advice would be greatly appreciated. Even an entirely different way of getting this data would be appreciated.
Also, I left only 4 of the datarow fields in the below code since it is failing on "First Name" to keep the code uncluttered. Since that would be the same reason for all of the other fields that are not comming back in my query.
Chris
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Client
Try
Dim cred = New SharePointOnlineCredentials(txtUserName.Text, secureString)
Dim ctx = New Microsoft.SharePoint.Client.ClientContext(siteUrl)
ctx.Credentials = cred
Dim web As Web = ctx.Web
Dim list As List = web.Lists.GetByTitle(siteList)
ctx.Load(list)
ctx.ExecuteQuery()
Dim query As CamlQuery = CamlQuery.CreateAllItemsQuery()
query.ViewXml = "<View Scope='RecursiveAll'><Query><ViewFields><FieldRef Name='First Name'/><FieldRef Name='Last Name'/><FieldRef Name='Office Phone'/><FieldRef Name='Email'/><FieldRef Name='Cell Phone'/><FieldRef Name='Department'/><FieldRef Name='Location'/></ViewFields></Query></View>"
Dim AllItems As ListItemCollection = list.GetItems(query)
ctx.Load(AllItems)
ctx.ExecuteQuery()
If AllItems.Count > 0 Then
Dim dt As New DataTable
Dim dRow As DataRow
Dim dcID As New DataColumn("Id")
dcID.DataType = Type.GetType("System.String")
Dim dcFName As New DataColumn("First Name")
dcFName.DataType = Type.GetType("System.String")
Dim dcLName As New DataColumn("Last Name")
dcLName.DataType = Type.GetType("System.String")
Dim dcTitle As New DataColumn("Title")
dcTitle.DataType = Type.GetType("System.String")
dt.Columns.Add(dcID)
dt.Columns.Add(dcFName)
dt.Columns.Add(dcLName)
dt.Columns.Add(dcTitle)
For Each item As ListItem In AllItems
dRow = dt.NewRow()
dRow("Id") = item.Id
dRow("First Name") = item("First Name")
dRow("Last Name") = item("Last Name")
dRow("Title") = item("Title")
dt.Rows.Add(dRow)
Next
DGVList.DataSource = dt
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Ok, it seems that the CAML was correct. I just did not know the internal names on the Sharepoint site. Once I obtained a list of the internal field names (not the display ones like I naively thought), I no longer ran into any errors. The answer was not so hard once I realized that I was querying fields that did not exist. It makes perfect sense that Visual Studio would yell at me for it.

VB.NET Screenshot Application Window and Send

I have built an application that obtains details from a web service and displays them in a GUI for the agent to see.
I've had instances of problems occuring, sometimes an exception due to a change in how the data is received due to the provider and unfortunately no user lets me know this occurs, they just click through and pay no attention to the error.
I've built a custom form to capture the error and then email it to me with some details like username etc. etc.
I would ideally LIKE to capture the screen of the application as well, much like an ALT+PRINTSCRN so I can see what the application looks like at the time of error as well.
How possible is this?
Assuming WinForm, I've done this before:
Public Sub SaveAsImage(frm As Form)
'Dim fileName As String = "sth.png"
'define fileName
Dim format As ImageFormat = ImageFormat.Png
Dim image = New Bitmap(frm.Width, frm.Height)
Using g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(frm.Location, New Point(0, 0), frm.Size)
End Using
image.Save(fileName, format)
End Sub
When being called, it will capture the current screen in the area defined by frm and save to a file.

Retrieve Lotus Notes Domino directoy groups and users

Using Studio 2013 VB.
I am attempting to retrieve group members from our Lotus Notes Domino directory - but I cannot get past this error: "A protocol error occurred. Failed, invalid authentication method specified." I was assuming (maybe incorrectly) that this could be done using DirectorySearcher as we do for our Active Directory.
I have tried retrieving various data with the same results. My research seems to indicate a problem with the ldapsettings but I am using the same alias and specific ldapsettings used by other in-house scripts (albeit written in perl). So the ldapsettings still might be the problem.
The line of code that fails is:
Dim result As SearchResult = searcher.FindOne
The value of searcher.Filter is (&(objectclass=dominoGroup)(cn=mydominogroup))
So this looks like it is build right.
Any help with errors in my code - or even suggestions to accomplish this task a better way are appreciated.
Here is my code:
dim grp as String = "mydominogroup"
Using dEntry As New DirectoryEntry("LDAP://mycompanyldapsettings")
dEntry.Username = myadminaccount
dEntry.Password = myadminpassword
Using searcher As New DirectorySearcher(dEntry)
searcher.Filter = String.Format("(&(objectclass=dominoGroup)(cn={0}))", grp)
Dim result As SearchResult = searcher.FindOne <--fails here
If result Is Nothing Then
"report group not found"
Else
Dim members As Object = result.GetDirectoryEntry.Invoke("Members", Nothing)
If members Is Nothing Then
"report no members found in group"
Else
For Each member As Object In CType(members, IEnumerable)
Dim currentMember As New DirectoryEntry(member)
If currentMember.SchemaClassName.ToLower = "user" Then
Dim props As PropertyCollection = currentMember.Properties
"get and list the user pros("someattribute").Value)"
End If
Next
End If
End If
End Using
End Using
Decided to call an external Process to solve this.