This blog is for Dynamics AX (AXAPTA) Developers,this will help you for your development issues. This site contains some Microsoft Dynamics AX X++ Codes for use in your day to day use.
22 September 2023
D365 F&O OData get call in Postman which is getting empty records even when we filtered with company in endpoint
18 September 2023
Export data entity or composite data entity using X++ code in D365 F&O
using System;
using System.Globalization;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Net.Http;
//using Windows.Web.Http;
internal final class TRGExportEntitySO
{
public static void main(Args _args)
{
TRGExportEntitySO entityExport = new TRGExportEntitySO();
entityExport.exportEntityData();
}
public void exportEntityData()
{
DMFDefinitionGroupEntity definitionGroupEntity,definitionGroupEnt;
DMFEntity dmfEntity,dmfEntityLoc;
CBBlobHelper helper = new CBBlobHelper();
#DMF
Query query;
DMFEntityName entityName = "Sales Orders Composite v3";
DMFDefinitionGroupName definitionGroupName = 'SO Export';//'Customer payment journal Exp';
SharedServiceUnitFileID fileId;
List xsltFileList = new List(Types::String);
boolean isGenerated = false;
select firstonly DefinitionGroup,Entity,Source from definitionGroupEnt
where definitionGroupEnt.DefinitionGroup == definitionGroupName
join TargetEntity from dmfEntityLoc
where dmfEntityLoc.EntityName == definitionGroupEnt.Entity
&& dmfEntityLoc.EntityType == DMFEntityTypes::CompositEntity;
//DMFEntity dmfEntityLoc = DMFEntity::find(definitionGroupEnt.Entity);
//entityName = DMFEntity::findFirstByTableId(tableNum(SalesOrderV3Entity)).EntityName;
// Update query
query = new query(dmfutil::getDefaultQueryForEntityV3(definitionGroupEnt.Entity,definitionGroupName));
//query = new query(this.getDefaultQueryForEntityV3(entityName));
querybuilddatasource qbds = query.datasourcetable(tablenum(SalesOrderHeaderV2Entity));
sysquery::findorcreaterange(qbds, fieldnum(SalesOrderHeaderV2Entity, SalesOrderNumber)).value("SOCN01-0000056"); // selected record value to be pass here
select firstonly RecId,Entity,DefinitionGroup from definitionGroupEntity
exists join dmfEntity
where definitionGroupEntity.DefinitionGroup == definitionGroupName
&& dmfEntity.entityName == definitionGroupEntity.entity
&& dmfEntity.TargetEntity == dmfEntityLoc.TargetEntity;//"SalesOrderV3Entity";
try
{
ttsbegin;
definitionGroupEntity.reread();
definitionGroupEntity.selectForUpdate(true);
definitionGroupEntity.QueryData = query.pack();
definitionGroupEntity.update();
ttscommit;
DMFEntityExporter exporter = new DMFEntityExporter();
fileId = exporter.exportToFile( definitionGroupEnt.Entity,
definitionGroupName,
"",
definitionGroupEnt.Source,//'CSV-Unicode',
#FieldGroupName_AllFields,
query.pack(),
curExt(),
null,
true,
false);
if (fileId != '')
{
//Get Azure blob url from guid
str downloadUrl = DMFDataPopulation::getAzureBlobReadUrl(str2Guid(fileId));
System.Uri uri = new System.Uri(downloadUrl);
str fileExt;
if (uri != null)
{
fileExt = System.IO.Path::GetExtension(uri.LocalPath);
}
Filename filename = strFmt('%1,%2',definitionGroupEnt.Entity,fileExt);
System.IO.Stream stream = File::UseFileFromURL(downloadUrl);
//Send the file to user
//File::SendFileToUser(stream, filename);
//filePath
//str connectStr = CBKeyVaultCertificateHelper::getManualSecretValue('https://smartcoredev-a9b3cnb8fph3hae2.z01.azurefd.net/d365?sv=2022-11-02&ss=b&srt=sco&sp=rwdlacyx&se=2024-04-01T18:49:49Z&st=2023-10-12T10:49:49Z&spr=https&sig=xvLiFCCg6JmHjJ1x6i2Eu%2BhEw1DWSetEKD6jZtRWgu4%3D');
str connenctionString = "https://smartcoredev-a9b3cnb8fph3hae2.z01.azurefd.net/d365/" + filename + "?sv=2022-11-02&ss=b&srt=sco&sp=rwdlacyx&se=2024-04-01T18:49:49Z&st=2023-10-12T10:49:49Z&spr=https&sig=xvLiFCCg6JmHjJ1x6i2Eu%2BhEw1DWSetEKD6jZtRWgu4%3D";
//str connectStr = "https://smartcoredev-a9b3cnb8fph3hae2.z01.azurefd.net/d365?sv=2022-11-02&ss=b&srt=sco&sp=rwdlacyx&se=2024-04-01T18:49:49Z&st=2023-10-12T10:49:49Z&spr=https&sig=xvLiFCCg6JmHjJ1x6i2Eu%2BhEw1DWSetEKD6jZtRWgu4%3D";
Uri blobUri = new Uri(connenctionString);
//try
//{
//using(System.Net.Http.HttpClient cl = new System.Net.Http.HttpClient())
// {
// System.Net.Http.HttpClient clien = new System.Net.Http.HttpClient();
// System.Net.Http.StreamContent content = new System.Net.Http.StreamContent(stream);
// //content.Headers.Add("x-ms-blob-type", "BlockBlob");
// //string mimeType = "text/plain";
// //content.Headers.Add("Content-Type", mimeType);
// var response = cl.PutAsync(blobUri, content).Result;
// if (!response.IsSuccessStatusCode)
// {
// throw new InvalidPluginExecutionException("Put request wasn't a success.");
// }
// }
//}
//catch (Exception e)
//{
// throw new InvalidPluginExecutionException("Your file upload wasn't successful.");
//}
helper.createBlobContainer(connenctionString,'');
helper.uploadBlobFileByStream("filename", stream);
DMFDefinitionGroup::find(definitionGroupName, true).delete();
isGenerated = true;
}
else
{
//throw error("The file was not generated succefully. See execution log");
}
}
catch
{
//throw error("DMF execution failed and details were written to the execution log");
}
}
}
16 September 2023
D365 F&O Data Management entity export for all companies data
On the dataEntity properties "Primary company Context" property set to "DataAreaId" that means it will export the data on the current company.
To export all companies data:
DataEntity properties "Primary company Context" property set to Emply that means it will export the data on the current company
04 September 2023
Query missing QueryBuildDataSource for FormDataSource PurchTable in PurchTable form in D365 F&O
Query missing QueryBuildDataSource for FormDataSource PurchTable
when there is a new table PurchTableTAR in D365 F&O
AP-> Purchase Orders assigned to me
When I open this its getting the below error.
Query missing QueryBuildDataSource for FormDataSource PurchTableTAR
as newly added table in PurchTable Form.
As shown below is the query to be added new table which is added in the form as a DataSource.
31 July 2023
Using Filter Expressions in OData URIs in D365 F&O
https://URL/data/CustomerGroups?$filter=CustomerGroupId eq '10'
https://URL/data/ResourceRequitionLines?filter=SFReqId eq '777787'
https://URL/data/ResourceRequitionLines?$filter=SFReqId eq @title&@title='777787'
24 July 2023
how to get the Inventory dimension combination ItemCategory in D365F&O
23 April 2023
Dynamics 365 F&O SysOperation Simple example
class FMCustService extends SysOperationServiceBase
{
public void
processCustomerData( FMCustContract _contract)
{
CustTable
custTable;
AccountNum
account = _contract.parmCustAccount();
while
select custTable
where
custTable.AccountNum == account
{
Info(strFmt("%1",custTable.AccountNum));
}
}
}
internal final class
FMCustController extends SysOperationServiceController
{
public static void
main(Args _args)
{
FMCustController
custController = new FMCustController(classStr(FMCustService),
methodStr(FMCustService,processCustomerData),SysOperationExecutionMode::Synchronous);
custController.startOperation();
}
///
<summary>
///
///
</summary>
///
<returns></returns>
public ClassDescription
caption()
{
ClassDescription
ret;
ret
= "Customer base operation";
return
ret;
}
}
[DataContractAttribute]
class FMCustContract
{
CustAccount
custAccount;
[DataMemberAttribute(identifierStr(CustAccount)),
SysOperationLabelAttribute(literalStr("Customer
account")) ]
public CustAccount
parmCustAccount(CustAccount _custAccount = CustAccount)
{
custAccount
= _custAccount;
return
custAccount;
}
}
16 March 2023
JSON file format to generate for outbound in Dynamics 365 F&O
JSON file format to generate for outbound:
Class: formJsonSerializer
Contract class: pickListHeaderContract , need to pass all required values to contract class.
02 March 2023
25 February 2023
13 February 2023
Form control value versioning view Manager and make bold the modified value in Form Control in D365 FO
x++ code to set bold of field value based on the modification in D365FO Form control
Form : PurchVendorPortalResponses
private void registerForChangeTracking()
{
viewManager = VersioningDocumentViewManager::construct();
viewManager.registerDataContainerForDataSource(PurchaseOrderResponseHeader_DS,
VersioningDocumentViewDataContainer::constructFromDataSource(
PurchaseOrderResponseHeader_DS,
[fieldStr(PurchaseOrderResponseHeaderAllVersions, PurchTableVersion)],
fieldStr(PurchaseOrderResponseHeaderAllVersions, VersionDateTime),
new PurchaseOrderResponseHeaderMapper()));
viewManager.registerDataContainerForDataSource(PurchaseOrderResponseLine_DS,
VersioningDocumentViewDataContainer::constructFromDataSource(
PurchaseOrderResponseLine_DS,
[fieldStr(PurchaseOrderResponseLineAllVersions, PurchTableVersion),
fieldStr(PurchaseOrderResponseLineAllVersions, PurchaseOrderResponseLine)],
fieldStr(PurchaseOrderResponseLineAllVersions, VersionDateTime),
new PurchaseOrderResponseLineMapper()));
viewManager.registerControlForTracking(PurchaseOrderResponseHeader_DlvTerm);
viewManager.registerControlForTracking(PurchaseOrderResponseHeader_DlvMode);
viewManager.registerControlForTracking(PurchaseOrderResponseHeader_VendorRef);
viewManager.registerControlForTracking(PurchaseOrderResponseLine_PurchQty);
viewManager.registerControlForTracking(PurchaseOrderResponseLine_ConfirmedDlv);
viewManager.registerControlForTracking(PurchaseOrderResponseLine_ExternalItemId);
viewManager.registerControlForTracking(PurchaseOrderResponseLine_Name);
}
=====
Extension to add extra feild.
/// <summary>
///
/// </summary>
[ExtensionOf(formstr(PurchVendorPortalResponses))]
final class TestPurchVendorPortalResponses_Extension
{
/// <summary>
///
/// </summary>
public void init()
{
next init();
viewManager.registerControlForTracking(PurchaseOrderResponseLine_PurchPrice);
}
}
====
Similarly:
Form: PurchVendorPortalAllResponse
Method: registerForChangeTracking()
Extenion to add new control for tracking and bold:
[ExtensionOf(formstr(PurchVendorPortalAllResponse))]
final class TestPurchVendorPortalAllResponse_Extension
{
public void init()
{
next init();
VersioningDocumentViewManager viewManager = this.getViewManager();
viewManager.registerControlForTracking(PurchaseOrderResponseLineAllVersions_PurchPrice);
}
}
Ledger Voucher creation Framework and x++ code to create ledger voucher
Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...
-
{ "Message" : "Please verify that the user is valid and set up correctly." } Sol: System Administration > Se...
-
Please click here to access Custom Workflow step by step process:
-
FormRun formRun = sender.formRun(); Object inventTrans_ds = formRun.dataSource(formDataSourceStr(InventMarking,InventTransO...