Wednesday, March 20, 2013

Cannot create a record in Project journal table (ProjJournalTable). Insert operations are not allowed across companies. Please use changecompany keyword to change the current company before inserting the record.

 Error

An unexpected error has occurred.


Dynamics Object Adapter Call failed.

Microsoft.Dynamics.Framework.BusinessConnector.Session.Exceptions.XppSessionException
   at Microsoft.Dynamics.Framework.BusinessConnector.Session.DynamicsSession.HandleException(String message, Exception exception, HandleExceptionCallback callback)
   at Microsoft.Dynamics.Framework.BusinessConnector.Session.DynamicsObjectAdapter.Call(String methodName)
   at TmpPwC_RASTable.ButtonPostHourJournal_Click(Object sender, EventArgs e) in c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\ep\TmpPwC_RASTable.ascx.cs:line 946
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

1101
Cannot create a record in Project journal table (ProjJournalTable).
Insert operations are not allowed across companies. Please use changecompany keyword to change the current company before inserting the record.


Microsoft.Dynamics.BusinessConnectorNet.XppException
   at Microsoft.Dynamics.BusinessConnectorNet.AxaptaObject.Call(String methodName, Object[] paramList)
   at Microsoft.Dynamics.Framework.BusinessConnector.Session.DynamicsObjectAdapter.Call(String methodName)


Issue

On usage of change company keyword also the table buffers will hold the old values, so its necessary to explicitly clear the table buffer by assigning null.

Resolution

changecompany(company)
{
            // nulling
            projParameters = null;
            projJournalTable = null;
            projJournalTrans = null;
            // nulling
            ttsbegin;
            projParameters  = ProjParameters::find();
            //further operations
}