Wednesday, April 8, 2020

Create Table Browser in D365 Finance and operations

Create Table Browser in D365 Finance and operations

Sometimes we might have to see the data in the tables, but as we know in case 0f cloud implementation of d365 finance and operations we do not have access to SQL server on production environment. Hence, we can not get from SQL. There was another option in AX 2012 R2 & AX 2012 R3, which is table browser. This option is not available on D365 finance and operation to check data from client, it is available from Visual Studio. 

This can be developed in D365 Finance and operations. Please follow below steps to create custom table browser:
1. Create a new form to project.
2. In the design apply custom pattern and content as shown in below image

3. Once you add String control table name and button Table browser, override the lookup method of TableName to give lookup from SQLDictionary table.
4. Then override the clicked method of TableBrowser to open the table browser for the table provided in TableName control.
5. Please find the code below for both the methods.
• Lookup method of TableName String control

public void lookup()
{
   Query                   query;
   QueryBuildDataSource    qbds;
   SysTableLookup          lookup;

   super();

   query = new Query();
   qbds = query.addDataSource(tableNum(SqlDictionary));
   lookup = SysTableLookup::newParameters(tableNum(SqlDictionary), this);
   qbds.clearRanges();
   qbds.addRange(fieldNum(SqlDictionary,fieldId )).value('0');
  lookup.addLookupfield(fieldNum(SqlDictionary, Name));
   lookup.addLookupfield(fieldNum(SqlDictionary, SqlName));
   lookup.parmQuery(query);
          lookup.performFormLookup();
   }

• Clicked method of TableBrowser button control

public void clicked()
       {           
           SysTableBrowser sysTableBrowser;            

           str tName;

           super();
           
           tName = TableName.valueStr();
           
           if (!tName)
           {
               throw    error(strfmt("@ApplicationFoundation:SysTableBrowser_MissingTableName"));

           }

           sysTableBrowser = new SysTableBrowser();
           sysTableBrowser.parmTableName(tName);
           sysTableBrowser.run(tablename2id(tName));
}
6. Once the form is ready, create menuitem of the form and attach to menu.
7. Find screenshots below:


You can then export that data to excel through standard export to excel feature.
Thank you for reading…!!!

X++ code Ignore SSL certificate validation d365 f&o


Ignore SSL certificate validation while calling api from d365 finance and operations

It is a common thing that some of your application functionalities depend on an external HTTPS endpoint. However, renewal of SSL certificate for the external party is out of your control and you have to rely on the third party that certificate will be renewed on time. If renewal does not happen on time, SSL certificate becomes invalid.Third party may not have valid SSL certificate for DEV/UAT environments.
.NET has by default build in mechanism to throw an exception if you are trying to make a web request to HTTPS endpoint which has invalid SSL certificate. In other words, .NET is doing SSL certificate validation for you under the hood.
The exception that you get is:
"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

Even if you try to access the URL to which you are trying to create a request in a browser you will get the following screen



You can resolve this issue by adding a custom validation method

private boolean validateCert(System.Object sender,X509Certificate    cert, X509Chain chain, SslPolicyErrors errors)
   {
       return true;
   }
In this example, validation method is overridden by custom method which always returns true value.
So before making a request, declare this callback method as shown below:

Private void apiCallMethod()
{
System.Net.Security.RemoteCertificateValidationCallback callBack;
       ​callBack += eventhandler(this.validateCert);       
       ​ServicePointManager::ServerCertificateValidationCallback = callBack;
System.Net.WebRequest           webreq = System.Net.WebRequest::Create(“api_url”);
Webreq.GetResponse();
}

This way, validation will always pass as your custom method always returns true value.
Thank you for reading,..!!!!