SELECT CUSTTABLE.ACCOUNTNUM AS CUSTID, DIRPARTYTABLE.NAME AS CUSTNAME,
CASE LOGISTICSELECTRONICADDRESS.TYPE WHEN 1 THEN 'Phone' WHEN 2 THEN 'Email' END AS CONTACTTYPE,
LOGISTICSELECTRONICADDRESS.DESCRIPTION AS CONTACTNAME, LOGISTICSELECTRONICADDRESS.LOCATOR AS CONTACTDETAILS
FROM DIRPARTYTABLE AS DIRPARTYTABLE INNER JOIN
CUSTTABLE ON DIRPARTYTABLE.RECID = CUSTTABLE.PARTY INNER JOIN
DIRPARTYLOCATION ON DIRPARTYTABLE.RECID = DIRPARTYLOCATION.PARTY INNER JOIN
LOGISTICSELECTRONICADDRESS ON DIRPARTYLOCATION.LOCATION = LOGISTICSELECTRONICADDRESS.LOCATION
ORDER BY DIRPARTYTABLE.NAME
Thursday, January 15, 2015
Customer contact list for AX2012
Query to extract a quick customer contact list from Dynamcis AX 2012
Monday, September 22, 2014
Consuming WCF web service from .NET assembly in Dynamics AX 2012
X++ code for consuming a WCF web service:
.NET Assembly
static server str serverSendToEndPoint(str _endPoint, str _soapAction, str _serverThumbprint, str _clientThumbprint, str _xmlString)
{
str ret;
System.String clrEndPoint;
System.String clrSoapAction;
System.String clrServerThumbprint, clrClientThumbprint;
System.String clrXmlString;
System.String clrResponse;
System.Exception ex;
Namespace.WebService webService;
try
{
webService = new Namespace.WebService();
clrEndPoint = CLRInterop::getObjectForAnyType(_endPoint);
clrSoapAction = CLRInterop::getObjectForAnyType(_soapAction);
clrServerThumbprint = CLRInterop::getObjectForAnyType(_serverThumbprint);
clrClientThumbprint = CLRInterop::getObjectForAnyType(_clientThumbprint);
clrXmlString = CLRInterop::getObjectForAnyType(_xmlString);
if (VendParameters::find().AVAMutualAuthentication == NoYes::Yes)
{
clrResponse = webService.callWCFWebService(clrEndPoint, clrSoapAction, clrServerThumbprint, clrClientThumbprint, clrXmlString);
}
else
{
clrResponse = webService.callWCFWebService(clrEndPoint, clrSoapAction, clrServerThumbprint, clrXmlString);
}
return CLRInterop::getAnyTypeForObject(clrResponse);
}
catch (Exception::CLRError)
{
ex = CLRInterop::getLastException();
throw error(strFmt("The request failed with the following response %1", CLRInterop::getAnyTypeForObject(ex.ToString())));
}
}
.NET Assembly
namespace Namespace
{
public class WebService
{
public String callWCFWebService(string url = "", string soapAction = "", string thumbPrint = "", string thumbPrint2 = "", string xmlString = "")
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
//Validate parameters
if (url == "")
{
throw new System.ArgumentException("Url missing");
}
if (soapAction == "")
{
throw new System.ArgumentException("Soap Action missing");
}
if (thumbPrint == "")
{
throw new System.ArgumentException("Server Thumbprint missing");
}
if (thumbPrint2 == "")
{
throw new System.ArgumentException("Client Thumbprint missing");
}
if (xmlString == "")
{
throw new System.ArgumentException("xmlString missing");
}
// Create a new HttpWebRequest object for the specified resource.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
// Request mutual authentication.
request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequired;
// Supply client credentials.
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.IncludeArchived);
// Find Server Certificate by thumbprint
X509Certificate2Collection col =
store.Certificates.Find(X509FindType.FindByThumbprint, thumbPrint.Replace(" ", ""), false);
X509Certificate2 cert = col.OfType<X509Certificate2>().FirstOrDefault();
if (cert == null)
{
throw new System.ArgumentException("Server Certificate not found in store ");
}
request.ClientCertificates.Add(cert);
// Find Client Certificate by thumbprint
col = store.Certificates.Find(X509FindType.FindByThumbprint, thumbPrint2.Replace(" ", ""), false);
cert = col.OfType<X509Certificate2>().FirstOrDefault();
store.Close();
if (cert == null)
{
throw new System.ArgumentException("Client Certificate not found in store");
}
request.ClientCertificates.Add(cert);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytesToWrite = encoding.GetBytes(xmlString);
request.Method = "POST";
request.ContentLength = bytesToWrite.Length;
request.Headers.Add("SOAPAction: \"" + soapAction + "\"");
request.ContentType = "text/xml; charset=utf-8";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.PreAuthenticate = true;
//Send Request
Stream dataStream = request.GetRequestStream();
dataStream.Write(bytesToWrite, 0, bytesToWrite.Length);
dataStream.Close();
//Get Response
string responseString = "";
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Read and display the response.
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
responseString = streamRead.ReadToEnd();
//Console.WriteLine(responseString);
// Close the stream objects.
streamResponse.Close();
streamRead.Close();
//Release the HttpWebResponse.
response.Close();
}
catch (Exception e)
{
if (e is WebException)
{
WebResponse errResp = ((WebException)e).Response;
if (errResp != null)
{
using (Stream streamResponse = errResp.GetResponseStream())
{
StreamReader streamRead = new StreamReader(streamResponse);
responseString = streamRead.ReadToEnd();
//Console.WriteLine(responseString);
// Close the stream objects.
streamResponse.Close();
streamRead.Close();
}
}
else
{
responseString = e.Message;
//Console.WriteLine(e.Message);
}
}
}
return responseString;
}
}
IIS 7.0 returns HTTP "403.13 Client Certificate Revoked" error message although certificate is not revoked
I had this error today with a web service configured with client certificates on IIS.
This issue happens when Certificate Revocation List (CRL) is enabled and the IIS server doesn't have Internet access
The following Microsoft support article describes the problem http://support.microsoft.com/kb/294305
CRL can be disabled via the following registry change:
This issue happens when Certificate Revocation List (CRL) is enabled and the IIS server doesn't have Internet access
The following Microsoft support article describes the problem http://support.microsoft.com/kb/294305
CRL can be disabled via the following registry change:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters\SslBindingInfo\0.0.0.0:443]DefaultSslCertCheckMode=1
Then Reboot the server for the change to take effect
Thursday, July 24, 2014
Dynamic date ranges for queries in AX
In Dynamics AX it is possible to enter dynamic date ranges for queries e.g. currentDate, day(-1) etc. which can be useful for running a daily report via a scheduled batch job.
The following example uses day(-1) to select Customer tax invoice journal records for yesterday
There are a number of dynamic data query values available in AX 2012, which can be found in the SysQueryRangeUtil class
The following example uses day(-1) to select Customer tax invoice journal records for yesterday
Wednesday, July 23, 2014
How to calculate time consumed running a process in X++
This code can be used to calculate the time consumed running a process
static void Job21(Args _args)
{
int startTime = timeNow();
int endTime;
sleep(5000);
endTime = timeNow();
info(strFmt("Process took %1", timeConsumed(startTime, endTime)));
}
Setting LedgerDimension field on LedgerJournalTrans table in AX 2012 via X++ code
The following code can be used to update LedgerDimension field on the LedgerJournalTrans
RecId getDimension(str _ledgerAccount, str _businessUnit, str _costCentre, str _jurisdiction, str _subscriberType)
{
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
if (_businessUnit)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('BusinessUnit') ;
ValueContract.parmValue(_businessUnit);
ListValueContract.addEnd(ValueContract);
}
if (_costCentre)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('CostCentre') ;
ValueContract.parmValue(_costCentre);
ListValueContract.addEnd(ValueContract);
}
if (_jurisdiction)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('Jurisdiction') ;
ValueContract.parmValue(_jurisdiction);
}
if (_subscriberType)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName('SubscriberType') ;
ValueContract.parmValue(_subscriberType);
ListValueContract.addEnd(ValueContract);
}
LedgerAccountContract.parmMainAccount(_ledgerAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
return dimensionAttributeValueCombination.RecId;
}
Setting Default Dimension using code in AX 2012
The following method can be used to set the default dimension e.g. on CustTable when importing data via X++
static DimensionDefault findDefaultDimension(str _businessUnit, str _costCentre, str _jurisdiction, str _subscriberType)
{
Struct struct = new Struct();
container defDimensionCon;
DimensionDefault dimensionDefault;
DimensionAttributeSetItem dimAttrSetItem;
DimensionAttribute dimAttribute;
int i;
//Read required dimensions
while select Name, BackingEntityType from dimAttribute
where dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) &&
dimAttribute.Type != DimensionAttributeType::DynamicAccount
join dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttribute.RecId &&
dimAttrSetItem.DimensionAttributeSet == DimensionCache::getDimensionAttributeSetForLedger()
{
//Add the Dimension name and value to struct
if (_businessUnit && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'BusinessUnit')
{
struct.add(dimAttribute.Name, _businessUnit);
}
if (_costCentre && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'CostCentre')
{
struct.add(dimAttribute.Name, _costCentre);
}
if (_jurisdiction && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'Jurisdiction')
{
struct.add(dimAttribute.Name, _jurisdiction);
}
if (_subscriberType && dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'SubscriberType')
{
struct.add(dimAttribute.Name, _subscriberType);
}
}
defDimensionCon += struct.fields();
for (i = 1; i <= struct.fields(); i++)
{
defDimensionCon += struct.fieldName(i);
defDimensionCon += struct.valueIndex(i);
}
if (struct.fields())
{
//Get the DimensionAttributeValueSet RecId
dimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(defDimensionCon);
}
return dimensionDefault;
}
Subscribe to:
Posts (Atom)

