Linx Main Linx Help

Xero CreateInvoice


#1

Hi,

I would greatly appreciate your help with some difficulty I’m having automating the creation of invoices in Xero. I successfully set various Invoice properties. However in addition to the Invoice properties, I have to pass through a list of the line items for the invoice.

The challenge I’m having is passing my dynamic LineItems list through to the Xero.Invoices.CreateInvoice function in a valid way.

I have built the list of line items using a string variable called x and lets consider the following example. Consider that x contains the following string data:

[{“Description”:“S BURGER BUNS”, “Quantity”:600.0, “UnitAmount”:2.0, “ItemCode”:“FBOO5”, “Tracking”:[{“Name”:“Stores”,“Option”:“ABC Burgers”}]},{“Description”:“S BURGER BUN 50G”, “Quantity”:30.0, “UnitAmount”:1.2066666667, “ItemCode”:“SBBB”, “Tracking”:[{“Name”:“Stores”,“Option”:“ABC Burgers”}]},{“Description”:“S HERO ROLL”, “Quantity”:6.0, “UnitAmount”:2.1, “ItemCode”:“FB001”, “Tracking”:[{“Name”:“Stores”,“Option”:“ABC Burgers”}]}]

In Xero.Invoices.CreateInvoice, I have set the LineItems property to “=x”, yet when I run my project I get the following error:

Could not cast or convert from System.String to System.Collections.Generic.List`1[Twenty57.Linx.Components.Xero.Entities.Common.Types.Compiled.LineItem]

However, if I literally paste in the above string data into the LineItems property, it works perfectly.

PS: I have also built a LIST variable and tried passing that through to the LineItems property instead of the above string variable x - but get the identical error message.


#2

Hi Leigh,

I just want to understand your scenario better.

For the Xero Invoice component, to send the LineItems, you need a “List” of “LineItems”. You can find the “LineItem” component under Xero -> Common -> LineItem:

00

Please let me know if you need more info.

Regards,
Dawie


#3

Hi Dawie,

I have tried that - built the list of line items into the Linx.List variable using Linx.AddToList.

However, when I pass that list variable to the LineItems property of the Xero.Invoices.CreateInvoice component I get the same error.

Regards,

Leigh


#4

Hi Leigh,

What is the type of your List?


#6

I’m building a list of Xero.Common.Lineitem entries…

image


#7

Here are the properties of AddLineItemToList…
Capture2


#8

Here I pass the list to Xero.Invoices.CreateInvoice…

Capture3


#9

And here is the error…

ImportStockPurchases.IfLastInvoiceValid: Error converting value “{“Description”:“S BURGER BUNS”,“Quantity”:600.0,“UnitAmount”:2.0,“ItemCode”:“FBOO5”,“AccountCode”:null,“LineItemID”:null,“TaxType”:null,“TaxAmount”:null,“LineAmount”:null,“Tracking”:[{“Name”:“Stores”,“Option”:“Watergate Steers”,“TrackingCategoryID”:null,“TrackingOptionID”:null}],“DiscountRate”:null}” to type ‘Twenty57.Linx.Components.Xero.Entities.Common.Types.Compiled.LineItem’. Path ‘LineItems[0]’, line 1, position 482.
Could not cast or convert from System.String to Twenty57.Linx.Components.Xero.Entities.Common.Types.Compiled.LineItem.


#10

Hi Leigh,

You’re 99% there. Just your List type needs to be a LineItem:


#12

Hoorah! Thank you I have found success!

Your help is truly appreciated.


#13

I’m finding that when I try and clear the list of lineitems to be ready for the next invoice, I now get the following error:

Object must implement IConvertible.

Capture5


#14

Hi Leigh,

Have you stepped through the process to see where the error occurs? I’ve tried the ClearList function on my side and it does work, so it might throw the error at another point.

To step through the process, right click on the first component and select “Add Breakpoint”. Then click on Debug, and step through the process. You can add breakpoints at more places through the process.

Dawie


#15

Hi Dawie,

Very wierd - I tried it again and it’s working although I haven’t made any changes.

Thanks for replying.