Hi all,
I am working on a requirement in AX 7 where I have to update few tables using OData services. I have created the entity for the particular table and made them public so that we can access the entities from the 3rd party applications. I have written wrapper service classes in C# to access these entities. I have been able to successful make read and insert. Now I have a requirement where I have to update certain records. It is throwing me an exception for update.
Sample code:
public string Save(List<FeedbackQuestion> feedbackList, string comment, string DataAreaId)
{
string flag = string.Empty;
string appointmentNo = feedbackList[0].AppointmentNo;
dataAreaId = string.IsNullOrEmpty(DataAreaId) ? dataAreaId : DataAreaId;
try
{
var query = from entity in _context.abc //"abc" is the entity from AX
where entity.AppointmentNo == appointmentNo && entity.DataAreaId == dataAreaId
select entity;
if (query.Count() > 0)
{
var feedbackQuestions = query.ToList();
foreach (var ap in feedbackQuestions)
{
foreach (var question in feedbackList)
{
if (question.Question.ToString() == ap.Question.ToString())
{
ap.AppointmentNo = appointmentNo;
ap.DataAreaId = dataAreaId;
ap.Answer = question.Answer;
_context.UpdateObject(ap);
_context.SaveChanges();
}
}
}
flag = "success";
}
}
catch (Exception ex)
{
flag = ex.ToString() + " " + ex.InnerException.ToString();
}
return flag;
}
Error message:
flag "Microsoft.OData.Client.DataServiceRequestException: An error occurred while processing this request. ---> Microsoft.OData.Client.DataServiceClientException: <!DOCTYPE html>\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n <title>Microsoft Dynamics AX</title>\r\n\t<link id=\"Theme_30_0\" href=\"/Resources/themes/30/0/core.min-7.0.4030.16079.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n <script>\r\n function goDashBoard() {\r\n window.location = \"/\"\r\n }\r\n </script> \r\n <style>\r\n \r\n html, body {\r\n min-height: 100%; /*Sets the min height to the height of the viewport.*/\r\n width: auto;\r\n height: 100%; \r\n }\r\n\r\n html>body, html>body .errorPage-wrapper {\r\n height: auto; /*this undoes the IE hack, hiding it\r\n from IE using the child selector*/\r\n }\r\n\r\n body {\r\n margin: 0;\r\n overflow:auto;\r\n }\r\n\r\n </style> \r\n</head>\r\n<body>\r\n\t<div class=\"errorPage-wrapper\">\r\n <div class=\"errorPage\">\r\n <div id=\"topic\" class=\"titleField\">There is a problem with the server</div> \r\n <div id=\"infomation\" class=\"mainInstruction\">Sorry, the server has encountered an error. It is either not available or it can't respond at this time. Please contact your system administrator.</div> \r\n </div>\r\n <div id=\"errorPage-footer\" class=\"errorPage-footer\">500 Error</div>\r\n\t</div>\r\n</body>\r\n\r\n</html>\r\n\r\n\r\n --- End of inner exception stack trace ---\r\n at Microsoft.OData.Client.SaveResult.HandleResponse()\r\n at Microsoft.OData.Client.BaseSaveResult.EndRequest()\r\n at Microsoft.OData.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)\r\n at Microsoft.OData.Client.DataServiceContext.SaveChanges()\r\n at DW.DAL.DynamicAX.AXCustomerRepository.SubmitFeedback(List`1 feedbackList, String comment, String DataAreaId) in C:\\Users\\axlocaladmin\\Documents\\Visual Studio 2015\\Projects\\Mobility\\MyCarCare\\DW.Dynamix.DAL\\AXCustomerRepository.cs:line 306 Microsoft.OData.Client.DataServiceClientException: <!DOCTYPE html>\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n <title>Microsoft Dynamics AX</title>\r\n\t<link id=\"Theme_30_0\" href=\"/Resources/themes/30/0/core.min-7.0.4030.16079.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n <script>\r\n function goDashBoard() {\r\n window.location = \"/\"\r\n }\r\n </script> \r\n <style>\r\n \r\n html, body {\r\n min-height: 100%; /*Sets the min height to the height of the viewport.*/\r\n width: auto;\r\n height: 100%; \r\n }\r\n\r\n html>body, html>body .errorPage-wrapper {\r\n height: auto; /*this undoes the IE hack, hiding it\r\n from IE using the child selector*/\r\n }\r\n\r\n body {\r\n margin: 0;\r\n overflow:auto;\r\n }\r\n\r\n </style> \r\n</head>\r\n<body>\r\n\t<div class=\"errorPage-wrapper\">\r\n <div class=\"errorPage\">\r\n <div id=\"topic\" class=\"titleField\">There is a problem with the server</div> \r\n <div id=\"infomation\" class=\"mainInstruction\">Sorry, the server has encountered an error. It is either not available or it can't respond at this time. Please contact your system administrator.</div> \r\n </div>\r\n <div id=\"errorPage-footer\" class=\"errorPage-footer\">500 Error</div>\r\n\t</div>\r\n</body>\r\n\r\n</html>\r\n\r\n" string
*This post is locked for comments