DEEP LINKS FOR SALES ORDERS
In this blog we will discuss about generating deep links for any form , record or datasource. Deep links are basically termed for generating URL's through code for any specific record in D365. Using Deep links other environments can access D365 records by using this URL generated from it.
1. In below blog I am creating Deep links for sales order header record.
2. To Access these links one should always be added the user in FinOps to access through URL.
Step #1 Create and extension class of URLUtility class and also add following code snippet to access this class :
using Microsoft.Dynamics.AX.Framework.Utilities;
using Microsoft.Dynamics.@Client.ServerForm.Contexts;
public static str generateRecordUrl(str _menuItemName, MenuItemType _menuItemType, DataSourceName _dataSourceName, Map _indexFieldValuesMap, DataAreaId _dataAreaId = curExt()) {
System.Uri host = SessionContext::Get_Current().Get_RequestUrl();
UrlHelper.UrlGenerator generator = new UrlHelper.UrlGenerator();
generator.MenuItemName = _menuItemName;
generator.MenuItemType = _menuItemType;
generator.HostUrl = host.GetLeftPart(System.UriPartial::Path);
generator.Company = _dataAreaId;
generator.EncryptRequestQuery = true;
if (_dataSourceName && _indexFieldValuesMap) {
MapEnumerator mapEnumerator = _indexFieldValuesMap.getEnumerator();
var requestQueryParameterCollection = generator.RequestQueryParameterCollection;
while (mapEnumerator.moveNext()) {
requestQueryParameterCollection.UpdateOrAddEntry(_dataSourceName, mapEnumerator.currentKey(), mapEnumerator.currentValue());
}
}
return generator.GenerateFullUrl().AbsoluteUri;
}
public static str generateRecordUrlFromDataSource(FormDataSource _formDataSource) {
FormRun formRun = _formDataSource.formRun();
str menuItemName = formRun.args().menuItemName();
MenuItemType menuItemType = formRun.args().menuItemType();
DataSourceName dataSourceName = _formDataSource.name();
TableId tableId = _formDataSource.table();
DictTable dictTable = new DictTable(tableId);
DictIndex dictIndex = new DictIndex(tableId, dictTable.primaryIndex());
int fieldCount = dictIndex.numberOfFields();
Map indexFieldValuesMap = new Map(Types::String, Types::String);
Common record = _formDataSource.cursor();
FieldId primaryKeyFieldId;
for (int fieldIndex = 1; fieldIndex <= fieldCount; fieldIndex++) {
primaryKeyFieldId = dictIndex.field(fieldIndex);
indexFieldValuesMap.insert(fieldId2Name(tableId, primaryKeyFieldId), any2Str(record.(primaryKeyFieldId)));
}
return URLUtility::generateRecordUrl(menuItemName, menuItemType, dataSourceName, indexFieldValuesMap, record.DataAreaId);
}
public static str generateUrl(Formrun formRun)
{
str url = next generateUrl(formRun);
if (formRun && formRun.dataSource(1) && formRun.dataSource(1).cursor())
{
url = URLUtility::generateRecordUrlFromDataSource(formRun.dataSource(1));
}
return url;
}
Step #2 Now you can call any of thes functions from any class or artifact in which u want to use it.
URL field should be of correct length
so make sure to check EDT of the field
Comments
Post a Comment