在创建销售订单后,我试图在发票时设置并激活合约。
但每次我尝试发布时,都会收到此错误。
该消息内容如下:
插入'合同'记录提出至少一个错误。请检查错误。错误:'合同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;
}
以下是合约模板和客户合约屏幕的截图。
答案 0 :(得分:1)