Показать сообщение отдельно
Старый 08.02.2012, 01:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,644 / 848 (80) +++++++
Регистрация: 28.10.2006
emeadaxsupport: Calling the Update Operation on the SalesOrderService
Источник: http://blogs.msdn.com/b/axsupport/ar...erservice.aspx
==============

The code is an example of how to call the update method on sales order in AX 2012 using the SalesOrderService.



static void Main(string[] args)

{

//First find the order

AxdSalesOrder salesOrder = Program.FindOrder();

//Now update it

Program.UpdateOrder(salesOrder);

}



static AxdSalesOrder FindOrder()

{

CallContext context = new CallContext();
context.Company = "ceu";



string salesId = "SO-101244";

AxdSalesOrder foundSalesOrder = null;



//Instantiate an instance of the service client class

SalesOrderServiceClient proxy = new SalesOrderServiceClient();

try

{


foundSalesOrder = proxy.find(context, Program.createQueryCriteria(salesId));


Console.WriteLine("The sales order was found.");

}

catch (Exception e)

{


Console.WriteLine("The sales order was not found.");

}



return foundSalesOrder;

}



private static QueryCriteria createQueryCriteria(string salesIdValue)

{

CriteriaElement[] criteriaElements = new CriteriaElement[1];


criteriaElements[0] = new CriteriaElement();


criteriaElements[0].DataSourceName = "SalesTable";


criteriaElements[0].FieldName = "SalesId";


criteriaElements[0].Value1 = salesIdValue;

QueryCriteria queryCriteria = new QueryCriteria();


queryCriteria.CriteriaElement = criteriaElements;

return queryCriteria;

}



static void UpdateOrder(AxdSalesOrder salesOrder)

{

CallContext context = new CallContext();


context.Company = "ceu";



SalesOrderServiceClient proxy = new SalesOrderServiceClient();

foreach (AxdEntity_SalesTable salesTable in salesOrder.SalesTable)

{


foreach (AxdEntity_SalesLine salesLine in salesTable.SalesLine)


{

salesLine.SalesQty = salesLine.SalesQty + 1;

salesLine.SalesPrice = salesLine.SalesPrice + 2;


salesLine.SalesPriceSpecified = true;


}

}



try

{


proxy.update(context, Program.createEntityKeyList(), salesOrder);


Console.WriteLine("The sales order was successfully updated");

}

catch (Exception e)

{


Console.WriteLine("The sales order was not updated.");

}

}



private static EntityKey[] createEntityKeyList()

{

EntityKey[] entityKeyList = new EntityKey[1];

EntityKey entityKey = new EntityKey();

KeyField[] keyDataList = new KeyField[1];

KeyField keyField = new KeyField();


keyField.Field = "SalesId";

keyField.Value = "SO-101244";


keyDataList[0] = keyField;


entityKey.KeyData = keyDataList;


entityKeyList[0] = entityKey;

return entityKeyList;

}






Источник: http://blogs.msdn.com/b/axsupport/ar...erservice.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.