Skip to main content

Deep Links

 

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.


I Added to virtual field and used in data entity extension class.




          HEY HEY HEY !!!! HACK OF DAY 
          URL field should be of correct length 
          so make sure to check EDT of the field

Comments

Popular posts from this blog

Edit Method on Form

Edit Method D365 for a form Data Source 1. To create an edit method first create a controller class. with following properties  public static edit MainAccountNum LedgerJournalTransLedger(LedgerJournalTrans _ledgerjournal, boolean _set, MainAccountNum _id) { MainAccountNum accountId = _id; MainAccount mainAccount = MainAccount::findByMainAccountId(_id); if(_set) { if(_ledgerjournal.AccountType== LedgerJournalACType::Ledger) { mainAccount = MainAccount::findByMainAccountId(accountId); if(_ledgerjournal.LedgerDimension) { DimensionDefault defaultDim = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(_ledgerjournal.LedgerDimension); _ledgerjournal.LedgerDimension = LedgerDimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(mainAccount.RecId, DimensionHierarchy::getAccountStructure(mainAccount.RecId), defaultDim); } else { _ledgerjournal.LedgerDimension = LedgerDimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(mainAccount.RecId, DimensionHierarchy::ge...

Lookup and Mandatory fields on Form using Form event Handlers D365

Lookup and Mandatory fields on Form using Form event Handlers D365 [FormControlEventHandler(formControlStr(VendBankAccounts, VendBankAccount_SLD_BankCode), FormControlEventType::Lookup)] public static void VendBankAccount_SLD_BankCode_OnLookup(FormControl sender, FormControlEventArgs e)     {         Query query = new Query();         QueryBuildDataSource queryBuildDataSource;         FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;         QueryBuildRange queryBuildRange;         SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(SLD_BankCodes), sender);         sysTableLookup.addSelectionField(fieldNum(SLD_BankCodes, BankCodes));         sysTableLookup.addLookupField(fieldNum(SLD_BankCodes, BankCodes));         sysTableLookup.addLookupField(fieldNum(SLD_BankCode...

Field Level Security In Ax 2012

FIELD LEVEL SECURITY IN AX 2012 In this blog we will discuss field level security applied in  Ax 2012. 1. Field level security is added on form level as well in Ax 2012 its bit different then field level security in D365 2. This also requires privileges to be applied on form specific fields only. Step #1 :  Change datasource property of the field which need to be added in security. Step #2 : Now add these 2 fields in form --- > permissions --- > Read Step #3 : Now finally create privilege and add these fields explicitly in it.       HEY HEY HEY !!!! HACK OF THE DAY  Add Fields in Entry point privilege section of form  Explicitly.