Object Reference Error when evaluating Calculation

Version 2

    Environment:

    Service Desk 7.3 and newer.

     

    Problem:

     

    Using a Before Save calculation gives you the following error message:

     

     

    NullReferenceException

    Object reference not set to an instance of an object.

     

    Stack Trace:

       at Touchpaper.Framework.Data.DataObjectCalculator.CalculateAttributeValue(IDataObject dataObject, String attributeName)

       at Touchpaper.Framework.Data.DataObjectCalculator.CalculateBeforeWriteAttributes(IDataObject dataObject)

       at Touchpaper.Framework.Data.DataObjectContext.PerformCalculations(IList listToUpdate, Boolean firstTime)

       at Touchpaper.Framework.Data.DataObjectContext.SaveChanges()

       at Touchpaper.Framework.Web.DataService.SaveChanges(SDataObjectContext sctxt, Boolean returnChanges)

     

     

    Solution:

     

    You have an attribute from a Collection Object set as the dependancy. You can't use an attribute on a collection as a dependency or you get issues like this when the calculation is trying to run even though it isn't relevant. You can use the collection itself as a dependency so that the calculation fires whenever a new collection item is created but not when a specific attribute on the collection is updated.