Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

how to get error log from AX after posting through c#

(0) ShareShare
ReportReport
Posted on by 10

I have created application to post General Journal with default Dimension on AX system

using service. But code not working and not posting any entry.

Can anyone tell me 'how to get error log from AX after posting through c#'.

Waiting for reply,

Momin

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: how to get error log from AX after posting through c#

    Perhaps we could continue the discussion in your other thread: community.dynamics.com/.../c-code-to-create-general-journal-with-default-dimension-not-working

    That's where your integration details are discussed. There's no point in discussing those details in two separate threads.

    In this thread you asked how to see AX error log in your C# application. As far as I can see, that question is answered. Whether AX error log contains the exact things that you would like is a different story. But showing AX error message in C# is working in your code as far as I know. Do you agree that the question is answered? If yes, could you please mark the helpful answer(s) as verified? Thanks!

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: how to get error log from AX after posting through c#

    Remember that your C# code calls x++ code. So you need to debug x++ code when you want to know what happens in AX.

    When debugging web service calls, you must use Visual Studio debugger, not the normal AX debugger.

    philippsen.wordpress.com/.../

  • Maisamali Momin Profile Picture
    Maisamali Momin 10 on at
    RE: how to get error log from AX after posting through c#

    how to debug our c# code on AX side ?

    does AX allows that ?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: how to get error log from AX after posting through c#

    No, there's no such thing in AX.

    Sometimes you get a more informative error message, sometimes a technical error message like now.

    There's not a system in the world that would always give perfect error messages in all situations. That's why you as a developer must debug it to understand the issue, and then fix your code so that it doesn't encounter this problem.

    Your code is not yet working, therefore your users can't use it and you don't need "business user friendly" message yet. Your current message is "developer friendly".

    Just debug your code on AX side to see where the error comes from.

  • Maisamali Momin Profile Picture
    Maisamali Momin 10 on at
    RE: how to get error log from AX after posting through c#

    No, My question is that the dynamics is giving me error as "Object reference not set to an instance of an object." But then this error does not point me to where i am wrong. How can i get logs from the dynamics system which will help me pin point where is exact problem

  • Maisamali Momin Profile Picture
    Maisamali Momin 10 on at
    RE: how to get error log from AX after posting through c#

    no nikolas.

    forget abt what error we are getting in c#.

    our question is does AX has any mechanism to give an error log or data log, when a third party app is trying to post a GL documemt using Http services.

    i am sure a system like Ax should have some tools and monitoring.

    we are hoping that it may give us some more info and not just generic object reference error.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: how to get error log from AX after posting through c#

    If AX sends this exception, then that's what you are going to get. You must eventually develop such solution that doesn't encounter this error. But the error message itself is quite clear and common.

    Remember that in your C# you can catch this exception and show something less technical to the user. "could not post journal xxx, please contact your administrator" or something like that. Right now your solution doesn't handle dimensions correctly but when it does, you will not get this exception anymore.

    But your original question "how to get error log from AX" seems answered.

  • Maisamali Momin Profile Picture
    Maisamali Momin 10 on at
    RE: how to get error log from AX after posting through c#

    yes still our issue is not solved.

    we have raised another ticket for Default dimension.

    we need to know more details for this Object reference error from AX side, how can we get that either in our c# code or AX side.

    we biliev there should be some way at AX side to get the error log for posting document through webservices.

    at C# side , if you could tell us any way to catch more specific AX exception.

    our integration was working fine till client asked that for some journal lines we have to pass Default Dimension and not Ledger dimension.

    Not sure what are we doing wrong in our c#code which is causing object reference error on .create

    please advise.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: how to get error log from AX after posting through c#

    Yes.

    But this means that you already have the AX "error log" (=error message) available in your C# code. Right?

    "Object reference not set to an instance of an object" is the AX error message.

    So do you still have some open question?

  • Maisamali Momin Profile Picture
    Maisamali Momin 10 on at
    RE: how to get error log from AX after posting through c#

    When we run below code,

    private bool PostTablewiseJV(PayrollArea Payrollarea, DataTable dt, string journalHeaderName)
    {
    	bool retFlag = false;
    	try
    	{
    		GeneralJournalServiceClient gjsClient = new AxGLService.GeneralJournalServiceClient();
    		CallContext context = new CallContext();
    
    		context.Company = Payrollarea.FICompany.Code;
    
    		AxdLedgerGeneralJournal journal = new AxdLedgerGeneralJournal();
    		AxdEntity_LedgerJournalTable journalHeader = new AxdEntity_LedgerJournalTable();
    		journalHeader.JournalName = "General";
    		journalHeader.Name = journalHeaderName;
    
    		AxdEntity_LedgerJournalTrans[] allTransaction = new AxdEntity_LedgerJournalTrans[dt.Rows.Count];
    
    		int count = 0;
    		foreach (DataRow dr in dt.Rows)
    		{
    			#region << Check StopFlag >>
    			//if (objSpace.GetObjectsQuery().Where(x => x.StopFlag).Any())
    			//{
    			//    break;
    			//}
    			#endregion
    
    			#region << Create Jv to Post >>
    			string Valid = Convert.ToString(dr["Valid"]);
    			string Companyaccounts = Convert.ToString(dr["Company accounts"]);
    			string Journalbatchnumber = Convert.ToString(dr["Journal batch number"]);
    			int RecId = Convert.ToInt32(dr["RecId"]);
    			int Linenumber = Convert.ToInt32(dr["Line number"]);
    			DateTime LinenumberDate = DateTime.ParseExact(Convert.ToString(dr["Line number.Date"]), "dd/MM/yyyy", CultureInfo.InvariantCulture);
    			string LinenumberAccounttype = Convert.ToString(dr["Line number.Account type"]);
    			string LedgerDimensionMainAccount = Convert.ToString(dr["LedgerDimension.MainAccount"]);
    			string LedgerDimensionMainAccountName = Convert.ToString(dr["LedgerDimension.MainAccountName"]);
    			string DefaultDimensionLocation = Convert.ToString(dr["DefaultDimension.Location"]);
    			string DefaultDimensionEmployees = Convert.ToString(dr["DefaultDimension.Employees"]);
    			string LedgerDimensionLocation = Convert.ToString(dr["LedgerDimension.Location"]);
    			string LedgerDimensionBrand = Convert.ToString(dr["LedgerDimension.Brand"]);
    			string LedgerDimensionDepartment = Convert.ToString(dr["LedgerDimension.Department"]);
    			string LedgerDimensionEmployees = Convert.ToString(dr["LedgerDimension.Employees"]);
    			string Currency = Convert.ToString(dr["Currency"]);
    			string Exchangerate = Convert.ToString(dr["Exchange rate"]);
    			decimal Debit = Convert.ToDecimal(dr["Debit"]);
    			decimal Credit = Convert.ToDecimal(dr["Credit"]);
    			string Description = Convert.ToString(dr["Description"]);
    			string Voucher = Convert.ToString(dr["Voucher"]);
    			string Offsetaccounttype = Convert.ToString(dr["Offset account type"]);
    			string OffsetLedgerDimensionMainAccount = Convert.ToString(dr["OffsetLedgerDimension.MainAccount"]);
    			string Offsetcompanyaccounts = Convert.ToString(dr["Offset company accounts"]);
    
    			AxdEntity_LedgerJournalTrans journalLine = new AxdEntity_LedgerJournalTrans();
    			journalLine.JournalNum = Journalbatchnumber;
    			journalLine.Company = Companyaccounts;
    			journalLine.AccountType = LinenumberAccounttype == "Ledger" ? AxdEnum_LedgerJournalACType.Ledger
    									: LinenumberAccounttype == "Bank" ? AxdEnum_LedgerJournalACType.Bank
    									: AxdEnum_LedgerJournalACType.Cust;
    			journalLine.AccountTypeSpecified = true;
    
    			//------LedgerDimension --------------------------------------------
    			AxdType_MultiTypeAccount account = new AxdType_MultiTypeAccount();
    			account.Account = LedgerDimensionMainAccount;
    			account.DisplayValue = LedgerDimensionMainAccountName;
    
    			AxdType_DimensionAttributeValue dimValue1 = new AxdType_DimensionAttributeValue();
    			dimValue1.Name = "Location";
    			dimValue1.Value = LedgerDimensionLocation;
    
    			AxdType_DimensionAttributeValue dimValue2 = new AxdType_DimensionAttributeValue();
    			dimValue2.Name = "Department";
    			dimValue2.Value = LedgerDimensionDepartment;
    
    			AxdType_DimensionAttributeValue dimValue3 = new AxdType_DimensionAttributeValue();
    			dimValue3.Name = "Employees";
    			dimValue3.Value = LedgerDimensionEmployees;
    
    			//AxdType_DimensionAttributeValue dimValue4 = new AxdType_DimensionAttributeValue();
    			//dimValue4.Name = "Brand";
    			//dimValue4.Value = LedgerDimensionBrand;
    
    			account.Values = new AxdType_DimensionAttributeValue[3] { dimValue1, dimValue2, dimValue3 };
    			journalLine.LedgerDimension = account;
    			//------LedgerDimension End--------------------------------------------
    
    			//------DefaultDimension--------------------------------------------
    			//AxdType_MultiTypeDefaultAccount defaultDimension = new AxdType_MultiTypeDefaultAccount();
    			//defaultDimension.Account = LedgerDimensionMainAccount;
    			//journalLine.DefaultDimension
    
    			AxdType_DimensionAttributeValueSet defaccount = new AxdType_DimensionAttributeValueSet();
    			AxdType_DimensionAttributeValue difdimValue1 = new AxdType_DimensionAttributeValue();
    			difdimValue1.Name = "Employees";
    			difdimValue1.Value = DefaultDimensionEmployees;
    
    			AxdType_DimensionAttributeValue difdimValue2 = new AxdType_DimensionAttributeValue();
    			difdimValue2.Name = "Location";
    			difdimValue2.Value = DefaultDimensionLocation;
    
    			defaccount.Values = new AxdType_DimensionAttributeValue[2] { difdimValue1, difdimValue2 };
    			journalLine.DefaultDimension = defaccount;
    			//------DefaultDimension End--------------------------------------------
    
    			journalLine.TransDate = LinenumberDate;
    			journalLine.TransDateSpecified = true;
    			journalLine.CurrencyCode = Currency;
    			journalLine.Txt = Description;
    
    			if (Debit > 0)
    			{
    				journalLine.AmountCurDebit = Debit;// 120;
    				journalLine.AmountCurDebitSpecified = true;
    			}
    			else
    			{
    				journalLine.AmountCurCredit = Credit;//120;
    				journalLine.AmountCurCreditSpecified = true;
    			}
    
    			allTransaction[count] = journalLine;
    			count = count   1;
    			#endregion
    		}
    
    		journalHeader.LedgerJournalTrans = allTransaction;
    		journal.LedgerJournalTable = new AxdEntity_LedgerJournalTable[1] { journalHeader };
    
    		string axuser = "";
    		string axpasswrd = "";
    		try
    		{
    			axuser = ConfigurationManager.AppSettings["FI_SYSTEM_USERNAME"].ToString();
    			axpasswrd = ConfigurationManager.AppSettings["FI_SYSTEM_PASSWORD"].ToString();
    		}
    		catch (Exception ex)
    		{ }
    		gjsClient.ClientCredentials.Windows.ClientCredential.UserName = axuser;
    		gjsClient.ClientCredentials.Windows.ClientCredential.Password = axpasswrd;
    
    		gjsClient.create(context, journal);
    
    		retFlag = true;
    	}
    	catch (Exception ex)
    	{
    		throw ex;
    	}
    
    	return retFlag;
    }

    so at line,

    gjsClient.create(context, journal);

    we got the exception message, '

    Object reference not set to an instance of an object'

    I hope now you got the point.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans