Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 73760

SalesLine item dont save for SalesTable

$
0
0

Hi,

 

I am working on CRMAX integration project.

I had written plugin on CRM Order entity to create SalesTable in AX.

And i write another plugin on CRM Order Products to update the SalesTable with SalesId.

It runs successfully. Debugged in. No error.

But the record is not inserted in SalesLine of that SalesTable in AX.

My code is as below for reference.


                    Guid orderId = ((EntityReference)orderproductEntity.Attributes["salesorderid"]).Id;                    
Entity
 _Order = _service.Retrieve("salesorder", orderId, new ColumnSet(new string[] { "new_pricegroup" }));                    // Create an instance of the document class.                    ax.AxdSalesOrder salesOrder = new ax.AxdSalesOrder();                    // Create instances of the entities that are used in the service and                    // set the needed fields on those entities.                    ax.AxdEntity_SalesTable salesTable = new ax.AxdEntity_SalesTable();                    salesTable.LanguageId = "en-in";                    salesTable.SalesStatus = ax.AxdEnum_SalesStatus.Backorder;                    salesTable.SalesStatusSpecified = true;                    salesTable.SalesType = ax.AxdEnum_SalesType.Sales;                    salesTable.SalesTypeSpecified = true;                    salesTable.PurchOrderFormNum = "PO";                                        //////******//////                    //////******//////                    ax.CriteriaElement[] criteriaElements = new ax.CriteriaElement[1];                    criteriaElements[0] = new ax.CriteriaElement();                    criteriaElements[0].DataSourceName = "SalesTable";                    criteriaElements[0].FieldName = "SalesId";                    criteriaElements[0].Value1 = _Order.Attributes["new_pricegroup"].ToString();                    ax.QueryCriteria queryCriteria = new ax.QueryCriteria();                    queryCriteria.CriteriaElement = criteriaElements;                    //////*****//////                    //////*****//////                    try                    {                        ax.AxdSalesOrder foundSalesOrder = null;                        foundSalesOrder = sc.find(queryCriteria);                        // Call the create method on the service passing in the document.                        //ax.EntityKey[] returnedSalesOrderEntityKey;                        //ax.KeyField salesorderId = new ax.KeyField();                        //salesorderId.Field = "SalesId";                        //salesorderId.Value = _Order.Attributes["new_pricegroup"].ToString();                        //ax.EntityKey myEntityKey = new ax.EntityKey();                        //myEntityKey.KeyData = new ax.KeyField[1] { salesorderId };                        //returnedSalesOrderEntityKey = new ax.EntityKey[1] { myEntityKey };                        ax.EntityKey[] entityKeyList = new ax.EntityKey[1];                        ax.EntityKey entityKey = new ax.EntityKey();                        ax.KeyField[] keyDataList = new ax.KeyField[1];                        ax.KeyField keyField = new ax.KeyField();                        keyField.Field = "SalesId";                        keyField.Value = _Order.Attributes["new_pricegroup"].ToString();                        keyDataList[0] = keyField;                        entityKey.KeyData = keyDataList;                        entityKeyList[0] = entityKey;                        //////*****//////                        //////*****//////                        ax.AxdEntity_SalesLine findsalesLine = null;                                                foreach (ax.AxdEntity_SalesTable findsalesTable in foundSalesOrder.SalesTable)                        {                            findsalesLine = new ax.AxdEntity_SalesLine();                            findsalesTable._DocumentHash = findsalesTable._DocumentHash;                            findsalesTable.RecId = findsalesTable.RecId;                            findsalesTable.RecVersion = findsalesTable.RecVersion;                                                        if (orderproductEntity.Attributes.Contains("productid"))                            {                                Guid productId = ((EntityReference)orderproductEntity.Attributes["productid"]).Id;                                Entity product = _service.Retrieve("product", productId, new ColumnSet("productnumber"));                                findsalesLine.ItemId = product.Attributes["productnumber"].ToString();                            }                            if (_Order.Attributes.Contains("new_pricegroup"))                            {                                string salesIdonProduct = _Order.Attributes["new_pricegroup"].ToString();                                findsalesLine.SalesId = salesIdonProduct;                            }                            findsalesLine.SalesUnit = "NOS";                                                        salesTable.SalesLine = new ax.AxdEntity_SalesLine[1] { findsalesLine };                            salesOrder.SalesTable = new ax.AxdEntity_SalesTable[1] { findsalesTable };                        }                        //////*****//////                        //////*****//////                        sc.update(entityKeyList, foundSalesOrder);                        // The create method returns an EntityKey which contains the ID of the sales order.                        //ax.EntityKey key = returnedSalesOrderEntityKey[0];                        //ax.KeyField kfld = key.KeyData[0];                        //orderproductEntity.Attributes["new_pricegroup"] = kfld.Value;                    }                    catch (Exception e)                    {                    }

 

 


Viewing all articles
Browse latest Browse all 73760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>