# Missing Sales Order Revenue Account when create Sales Order through code.

**URL:** <https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133>\
**Category:** Developer Forum\
**Created:** [March 14, 2016, 8:07am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133 "2016-03-14T08:07:27Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 14, 2016, 8:07am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/1 "2016-03-14T08:07:27Z")

</div>

Hi,

When I created and invoiced Sales Order through [code](http://dynamics.folio3.com/2015/05/08/creating-sales-order-in-dynamics-ax-2012-through-x/), I have found the logic error is missing Revenue Account value. In my case, the revenue account is 51110000.[1781.no.bmp](https://www.dynamicsuser.net/uploads/short-url/hpowJoySN4cB81v4AlPtifnzuzc.bmp) (1.25 MB)

But if I create SO by system form in Sales and Marketing or in Account Receivable, I can see Revenue Account .

[7115.no - Copy.bmp](https://www.dynamicsuser.net/uploads/short-url/tiJ5xnZ1iOwJ9bIWiNfKlqWJyIz.bmp) (1.25 MB)

Can anyone help me to create Sales Order through code (X++) and don’t miss Revenue Account.

Thanks.

Dat.

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [March 14, 2016, 9:19am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/2 "2016-03-14T09:19:38Z")

</div>

So to which account the customer revenue is being posted?

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 14, 2016, 9:27am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/3 "2016-03-14T09:27:23Z")

</div>

Hi Kranthi,

They are account 33311000 and 13110000.

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [March 14, 2016, 12:09pm UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/4 "2016-03-14T12:09:51Z")

</div>

Generally the invoice should update the sales revenue account. Is it not updated in your case? If so what is happening in your case?

Explain the voucher.

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 15, 2016, 2:10am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/5 "2016-03-15T02:10:22Z")

</div>

Oh, how can I update again sales revenue account. I think it is automatic when invoice are generated. In my case, I use **salesTable.initFromCustTable()** function to create SO header and **salesLine.createLine()** function to create sales order details, and use the **SalesFormLetter** class to invoice sales order.

There are many available codes for it, I have tried many but it has got the same error. Is my system in error.

Thanks.

---

<div class="post-metadata">

**Author:** ![ndhangar](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@ndhangar](https://www.dynamicsuser.net/u/ndhangar)\
**Post date:** [March 15, 2016, 3:55am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/6 "2016-03-15T03:55:33Z")

</div>

Did you try debugging the code ?

You can debug when invoicing through standard process which AX supports and debug your code and try to compare where it is going wrong

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 15, 2016, 4:00am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/7 "2016-03-15T04:00:57Z")

</div>

Hi Nash,

Thanks for your help, I know how to debug my code, but don’t know debug the standard process, can you tell me how to debug the standard process of AX.

Dat,

---

<div class="post-metadata">

**Author:** ![ndhangar](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@ndhangar](https://www.dynamicsuser.net/u/ndhangar)\
**Post date:** [March 15, 2016, 5:16am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/8 "2016-03-15T05:16:26Z")

</div>

Place the breakpoint in sales order invoice button clicked and try to invoice the sales order, then debugger hits the breakpoint then you can debug step by step

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [March 15, 2016, 6:06am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/9 "2016-03-15T06:06:45Z")

</div>

> [@](#):
>
> Oh, how can I update again sales revenue account.

You have not explained about the voucher.

But to understand which process has problem.

1. create sales order through code and post it manually.

2. Create sales order manually and post it through code.

then debug the fault process.

the posting of invoice happens in \Classes\SalesInvoiceJournalPost

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 15, 2016, 6:47am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/10 "2016-03-15T06:47:09Z")

</div>

Kranthi,

I also don’t have enough understand about the voucher to explain to you, your suggest is good, I will try and contact you again.

Thanks,

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 15, 2016, 8:07am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/11 "2016-03-15T08:07:52Z")

</div>

Kranthi,

I try your solution and find the error in my code, that is **SalesPrice** field in **SalesLine** table are not init when I call **createLine()** function.

Thank you very much!

Best Regard,

Dat

---

<div class="post-metadata">

**Author:** ![ndhangar](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@ndhangar](https://www.dynamicsuser.net/u/ndhangar)\
**Post date:** [March 15, 2016, 4:46pm UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/12 "2016-03-15T16:46:01Z")

</div>

Then fill in the salesPrice before creating the salesLine,

eg :

salesLine.SalesPrice = 20.0 ( your desired value)

salesLine.createLine(,);

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 16, 2016, 8:48am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/13 "2016-03-16T08:48:40Z")

</div>

Hi Nash,

My error code also set salesLine.SalesPrice before call salesLine.createLine, but after call createLine() function, I check again salesLine.SalesPrice, it is zero. May this function reset the value of sales price.

My solution is override the value of sales prices after call createLine, I use select for update statement. It work in fine.

Thanks and Regard,

Dat

---

<div class="post-metadata">

**Author:** ![ndhangar](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@ndhangar](https://www.dynamicsuser.net/u/ndhangar)\
**Post date:** [March 16, 2016, 10:36pm UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/14 "2016-03-16T22:36:15Z")

</div>

Hi Dat,

Can you tell me what are the parameters you are passing, the price changing is also dependent in 6th parameter

which you have to pass it as false if you do not want to override. So this way you dont have to update the price again.

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 17, 2016, 1:42am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/15 "2016-03-17T01:42:47Z")

</div>

Hi Nash,

I set “ **true** ” value for all parameter in createLine() function:

**salesLine.createLine(**

**true, // Validate**

**true, // initFromSalesTable**

**true, // initFromInventTable**

**true, // calcInventQty**

**true, // searchMarkup**

**true // searchPrice**

**);**

Thanks,

Dat

---

<div class="post-metadata">

**Author:** ![ndhangar](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@ndhangar](https://www.dynamicsuser.net/u/ndhangar)\
**Post date:** [March 17, 2016, 2:04am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/16 "2016-03-17T02:04:31Z")

</div>

**salesLine.createLine(**

**true, // Validate**

**true, // initFromSalesTable**

**true, // initFromInventTable**

**true, // calcInventQty**

**true, // searchMarkup**

**false// searchPrice**

**);**

**Try the above pass false for searchPrice that way you don’t have to update the price after creating the salesline**

---

<div class="post-metadata">

**Author:** ![HadesedaH](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@HadesedaH](https://www.dynamicsuser.net/u/HadesedaH)\
**Post date:** [March 17, 2016, 3:16am UTC](https://www.dynamicsuser.net/t/missing-sales-order-revenue-account-when-create-sales-order-through-code/60133/17 "2016-03-17T03:16:21Z")

</div>

Thanks Nash,

I have tried and it work in fine.

Best Regards,

Dat
