从合同模板中获取合同ID时出错

时间:2017-07-14 17:31:27

标签: acumatica

在创建销售订单后,我试图在发票时设置并激活合约。

但每次我尝试发布时,都会收到此错误。

enter image description here

该消息内容如下:

  

插入'合同'记录提出至少一个错误。请检查错误。错误:'合同ID'不能为空。

但在此之前,我已经为客户制定了合同模板和客户合同,并使用了合同模板。

以下是引发此错误的代码。

private Contract CreateActivateContract(ContractMaint contractMaint, DateTime? invoiceDate, int? customerID, int? customerLocationID, string simCardID, string phoneNumber, CTBillEngine engine)
    {
      contractMaint.Clear();
      //initialize new contract
      Contract contract = (Contract)contractMaint.Contracts.Cache.CreateInstance();
      contract = contractMaint.Contracts.Insert(contract);

      //look up contract template id
      Contract template = PXSelect<Contract,
                          Where<Contract.isTemplate, Equal<boolTrue>,
                          And<Contract.contractCD, Equal<Required<Contract.contractCD>>>>>
                          .Select(Base, "SIMCARD");
      if(template==null)
      {
         throw new PXException("The SIMCARD contract template was not found."); 
      }

      contract.TemplateID = template.ContractID;
      contract.CustomerID = customerID;
      contract = contractMaint.Contracts.Update(contract);
      contract.LocationID = customerLocationID;
      contract.StartDate = invoiceDate;
      contract.ActivationDate = invoiceDate;
      contract = contractMaint.Contracts.Update(contract);

      //store simcardid and phone number into the contract attributes
      foreach(CSAnswers attribute in contractMaint.Answers.Select())
      {
        switch(attribute.AttributeID)
        {
          case "SIMCARDID":
            attribute.Value = simCardID;
            contractMaint.Answers.Update(attribute);
            break;
          case "PHONENUM":
            attribute.Value = phoneNumber;
            contractMaint.Answers.Update(attribute);
            break;
        }
      }
      //save the generated contract
      contractMaint.Save.Press();
      //setup and actiave the contract
      engine.SetupAndActivate(contract.ContractID, contract.ActivationDate);
      return contract;

    }  

以下是合约模板和客户合约屏幕的截图。

https://i.stack.imgur.com/yw1bo.jpg

1 个答案:

答案 0 :(得分:1)

很可能您在CONTRACT分段键上禁用了自动编号: enter image description here

如果是这种情况,您的两个选项是:

  1. 启用CONTRACT分段密钥的自动编号

  2. 修改CreateActivateContract方法,为contract.ContactID指定唯一标识符:

    Contract contract =(Contract)contractMaint.Contracts.Cache.CreateInstance();
    contract.ContactID = "SOMEKEY";
    contract = contractMaint.Contracts.Insert(contract);