Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error on custom invoice workflow

(0) ShareShare
ReportReport
Posted on by 1,695

I have created a custom workflow to auto-generate invoices however, although the invoices are being generated, no items are included . I'm a bit perplexed as to why

Try

                            ' Get Product ID

                            Dim rtnProductid As String = String.Empty

                            Dim _productfilter As FilterExpression = New FilterExpression(LogicalOperator.And)

                            _productfilter.AddCondition("productnumber", ConditionOperator.Equal, "IAS" & Right("000000" & Replace(CStr(Format(_annualsupportfee, "##0.00")), ".", ""), 6))

                            Dim _annualsupportid As QueryExpression = New QueryExpression("product")

                            _annualsupportid.ColumnSet = New ColumnSet("productid")

                            _annualsupportid.Criteria = _productfilter

                            WriteToErrorLog("1. " & "IAS" & Right("000000" & Replace(CStr(Format(_annualsupportfee, "##0.00")), ".", ""), 6))

                            Dim returned_monthlysupportid As EntityCollection = _service.RetrieveMultiple(_annualsupportid)

                            If returned_monthlysupportid.Entities.Count > 0 Then

                                For Each returnedRecord In returned_monthlysupportid.Entities

                                    rtnProductid = returnedRecord.Attributes("productid").ToString

                                    WriteToErrorLog("2. " & returnedRecord.Attributes("productid").ToString)

                                    Exit For

                                Next

                                Dim invoiceDetail = New Entity("invoicedetail")

                                invoiceDetail("invoiceid") = New EntityReference("invoice", New Guid(invoiceid.ToString))

                                invoiceDetail("productid") = New EntityReference("product", New Guid(rtnProductid.ToString))

                                invoiceDetail("quantity") = CDec(1.0)

                                invoiceDetail("isproductoverridden") = False

                                invoiceDetail("uomid") = New EntityReference("uom", New Guid(Invoicelink))

                                _service.Create(invoiceDetail)

                                Return True

                            End If

                        Catch ex As Exception

                            WriteToErrorLog("3. " & ex.Message.ToString)

                        End Try

In my 'log' I get

1. IAS010000
2. 4394f419-3eb9-e911-9148-0050560105a7
3. The specified unit is not valid for this product.

I can see that the product is being found and I have doublechecked the id is correct, but I have no idea as to what 'The specified unit is not valid for this product' means. I am getting this error for all products

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans