web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    The question is perhaps more: "how to send error log from AX when journal is posted via custom service?".

    Your x++ code should return / expose the error message so that the external application can get it.

    Perhaps your x++ service could return an object that has status code and error message.

  • Maisamali Momin Profile Picture
    10 on at

    Thanks for your reply.

    we are trying to integrate Posting with our asp.net application , thats why we are using GL http service and coding through C# .net and not x++.

    We are successfully posted entry, but when we are using default dimension in our code then system is giving error 'Object reference not set to instance of an object'.

    With same code for Default Dimension, if i manually export the posting file as excel and give to client they can successfully post it manually.

    So need to know where we are wrong in our c# code.

    The Code that i have done for Default Dimension is as below.

    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;

    journalLine.DefaultDimension = defaccount;

    When i am trying to post this, 'i received Object reference not set to an instance of an object.'

    Can you help what is wrong in above code?

    Regards,

    Momin

    Excel file that we have posted successfully.
    [View:/cfs-file/__key/communityserver-discussions-components-files/33/CostFile_5F00_June_2D00_2020_5F00_Emp-104-_2D00_-Copy.xls:320:240]

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi,

    you have posted another question regarding your code: community.dynamics.com/.../1073593

    Let's keep the discussion about your code there.

    Here you asked "how to get error log from AX after posting through C#".

    So, are you having difficulties in seeing the " 'Object reference not set to instance of an object'." error in your C# application?

  • Maisamali Momin Profile Picture
    10 on at

    How to get error log on Posting from AX system (posting through web services)

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi,

    did you have time to go through the question that I asked in my previous reply?

    Could you please check it one more time and answer it. Thanks!

  • Maisamali Momin Profile Picture
    10 on at

    Hi,

    I have debbuged all the code and found that when query executes the code,

    gjsClient.create(context, journal);

    The error i got from AX system side. So need to know the exact issue which we are posting on AX system.

    thanks

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    I'm sorry but I still don't understand.

    Perhaps you could share a screenshot of the exception message that you see in C#, that would help me understand your situation.

    Thanks!

  • Maisamali Momin Profile Picture
    10 on at

    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.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    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
    10 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans