Erorr: Ex40105Exception: "You must specify a posting type nominal code" while creating new project

SOLVED

Hi All,

I want to add new project programmatically and is following this tutorial https://my.sage.co.uk/Sage200SDKDocs/html/DOC0354_Example.html#NEWPROJECT

Below are my code:

private PCProjectAdjustmentItem CreateCostAdjustmentItem(PCProjectCostAdjustment coordinator,
    string projectCode, string costItem, string narrative, string accountReference, string costCentre, 
    string Department, decimal goodsValue, DateTime transactionDate)
{
    PCProjectAdjustmentItem item = (PCProjectAdjustmentItem)coordinator.ProjectAdjustmentItems.AddNew();
    try
    {
        item.Project = PCProjectFactory.Factory.Fetch(projectCode);
        
        PCCostRevenueSummaryViews views = PCCostRevenueSummaryViews.CreateNew(
            CostRevenueAnalysisEnum.Cost, ProjectEnquiryGroupingEnum.ProjectCostItem);
        views.Query.Filters.Add(new Sage.ObjectStore.Filter(PCCostRevenueSummaryView.FIELD_PARENTPROJECTITEMCODE, projectCode));
        views.Query.Filters.Add(new Sage.ObjectStore.Filter(PCCostRevenueSummaryView.FIELD_PROJECTITEMCODE, costItem));
        views.Find();

        PCCostRevenueSummaryView view = views.First;
        item.ProjectCostItem = PCProjectCostItemFactory.Factory.Fetch(view.PCProjectItemID);
        
        item.Narrative = narrative;
        item.TransactionDate = transactionDate;
        
        Sage.Accounting.Common.NominalSpecification accountNominalSpecification =
            Sage.Accounting.Common.NominalSpecificationFactory.Factory.CreateNew(accountReference, costCentre, Department);
        item.NominalSpecification = accountNominalSpecification;
        
        item.GoodsValue = goodsValue;
    }catch(Exception ex)
    {
        Logger.WriteLog("Error in CreateCostAdjustmentItem goods value["+ goodsValue + "] - "+ex.ToString()+";");
        throw ex;
    }
    return item;
}

However, I get this error:

Sage.Accounting.Exceptions.Ex40105Exception: You must specify a posting type nominal code.
   at Sage.Common.DataAccess.BusinessObject.OnValidated(ValidatedEventArgs e)
   at Sage.Common.Rules.ErrorPropertyRuleAction.DefaultInvalidRuleAction()
   at Sage.Common.Rules.RuleAction.PerformAssociatedAction(ValidRuleAction validRuleAction, InvalidRuleAction invalidRuleAction)
   at Sage.Accounting.ProjectCosting.PCProjectAdjustmentItem.ValidateNominalSpecification(NominalSpecification nominalSpecification, RuleActionType ruleActionType, String fieldName)
   at Sage.Accounting.ProjectCosting.PCProjectAdjustmentItem.set_NominalSpecification(NominalSpecification value)
   at GLProjectAccrual.Forms.ImportCostRevAdjTemplateForm.CreateCostAdjustmentItem(PCProjectCostAdjustment coordinator, String projectCode, String costItem, String narrative, String accountReference, String costCentre, String Department, Decimal goodsValue, DateTime transactionDate);

But I did not found any variable related to posting type nominal code. What are the value to set and to set it which variable? Thank you.

  • +1
    verified answer

    In the code you've provided you're creating a NominalSpecification, and then passing this to the PCProjectAdjustmentItem.

    A NominalSpecification isn't a NominalCode. It's a lightweight object containing three strings that represent the Code, CostCentre and Department of what may or may not be an actual NominalCode. You can create a NominalSpecification using any old values you like and that in itself won't raise any kind of error:

    var nomSpec = NominalSpecificationFactory.Factory.CreateNew("MADE", "UP", "ACC");

    When you set the NominalSpecifcation property of PCProjectAdjustmentItem then Sage 200 will do a couple of things. First it'll try to find the actual nominal code which matches the CODE/CC/DEPT of the NominalSpecification. In my example this would fail, as I don't have a nominal code called 'MADE/UP/ACC'. If it does find a valid code then it'll check that it's a posting account (as opposed to a Group or Memo account - you'll see this when you edit a nominal code; it's the 'Account type'field).

    The Ex40105Exception will get raised if either of those checks fail. So it might not actually be the case that the nominal code isn't a posting account. It might simply be the case that it doesn't exist - because the combination of AccountReference, CostCentre and Department that you've passed into the method doesn't correspond to an actual nominal code.