try
{
ttsbegin;
{
Microsoft.Dynamics.Ax.Xpp.List dataList = new Microsoft.Dynamics.Ax.Xpp.List(Microsoft.Dynamics.Ax.Xpp.Types::Record);
Microsoft.Dynamics.Ax.Xpp.List itemList = new Microsoft.Dynamics.Ax.Xpp.List(Microsoft.Dynamics.Ax.Xpp.Types::Record);Microsoft.Dynamics.Ax.Xpp.ListIterator dataListIterator;
Microsoft.Dynamics.Ax.Xpp.ListIterator itemListIterator;
Microsoft.Dynamics.Ax.Xpp.ListIterator piovttIterator;BIAPISetup _apiSetup;
select firstonly _apiSetup order by _apiSetup.RecId desc ;
date requestDate;
str requeststr;
int numofdays;BIInventCountsContracrt _inventCountsContracrt= new BIInventCountsContracrt();
BIInventCountsData _inventCountsData= new BIInventCountsData();
BIInventCountItemData _inventCountItemData= new BIInventCountItemData();
BIBranchData _branchData= new BIBranchData();
BIInventCountPivotData _piovtData= new BIInventCountPivotData();RecordInsertList TransactionCountsList;
BITransactionCounts transactionCounts ;
TransactionCountsList = new RecordInsertList(tableNum(BITransactionCounts));numofdays =_apiSetup.NumberOfDays;
requestDate = today()- numofdays;
requeststr = strFmt(“/inventory_counts?&filter[business_date_after]= %1&include=items,branch”,requestDate);
// requeststr = strFmt(“/inventory_counts?filter[business_date]=2022-02-28&include=items,branch”);str Url =_apiSetup.BaseUrl+ requeststr;
str Base_Authorization = _apiSetup.Token;
var _client = new RestClient(Url);
_client.Timeout = -1;
var request = new RestRequest(0);
request.AddHeader(“token_type”, “Bearer”);
request.AddHeader(“Authorization”, Base_Authorization );
IRestResponse response = _client.Execute(request);if(response.StatusCode == 200)
{
str result = response.Content;_inventCountsContracrt = FormJsonSerializer::deserializeObject(classNum(BIInventCountsContracrt),result);
dataList = _inventCountsContracrt.data();
dataListIterator = new Microsoft.Dynamics.Ax.Xpp.ListIterator (dataList);while (dataListIterator.more())
{
_inventCountsData = dataListIterator.Value();_branchData = _inventCountsData.branch();
transactionCounts.TransId =_inventCountsData.id();
transactionCounts.BusinessDateStr =_inventCountsData.business_date();
transactionCounts.Branch =_branchData.id();// for items per record
itemList = _inventCountsData.items();
itemListIterator = new Microsoft.Dynamics.Ax.Xpp.ListIterator (itemList);while (itemListIterator.more())
{
_inventCountItemData= itemListIterator.Value();
_piovtData =_inventCountItemData.pivot();transactionCounts.ItemSKU=_inventCountItemData.sku();
transactionCounts.qty=_piovtData.quantity();TransactionCountsList.add(transactionCounts);
itemListIterator.Next();
}
dataListIterator.next();
}TransactionCountsList.insertDatabase();
}
else
{
warning(“Request not found”);
}}
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}