Question

Records deleting when pressing save

  • 29 April 2021
  • 1 reply
  • 17 views

Good day.

I have created a new form tab(Project Sub-Tasks) with two tabs on it, BillOfQuantity and SubContractorQuotes.

Both of the tabs should save and then write into the costbudget of the project it is linked to, this works fine.
My error comes in when I press the save icon on the SubContractorQuotes screen. It deletes all my records that I have entered into the grid. This problem does not occur within the BillOfQuantity screen.

Please see my DAC’s below:

   

[PXCacheName("Bill Of Quantities")]

public class PMBillOfQuantity : IBqlTable
{
#region BillOfQuantityID
[PXDBIdentity]
[PXUIField(DisplayName = "Bill Of Quantity ID")]
public virtual int? BillOfQuantityID { get; set; }
public abstract class billOfQuantityID : PX.Data.BQL.BqlInt.Field<billOfQuantityID> { }
#endregion

#region SubTaskId
[PXDBInt]
[PXUIField(DisplayName = "Sub Task Id")]
[PXDefault(typeof(Current<PMSubTask.subTaskID>))]
public virtual int? SubTaskId { get; set; }
public abstract class subTaskId : PX.Data.BQL.BqlInt.Field<subTaskId> { }
#endregion

#region InventoryId
[Inventory(IsKey = true)]
[PXRestrictor(typeof(Where<InventoryItem.stkItem, Equal<False>>),
null)]
[PXUIField(DisplayName = "Inventory Id")]

public virtual int? InventoryId { get; set; }
public abstract class inventoryId : PX.Data.BQL.BqlInt.Field<inventoryId> { }
#endregion

#region Description
[PXDBString(250, InputMask = "")]
[PXUIField(DisplayName = "Description")]
public virtual string Description { get; set; }
public abstract class description : PX.Data.BQL.BqlString.Field<description> { }
#endregion

#region Quantity
[PXDBInt()]
[PXUIField(DisplayName = "Quantity")]
public virtual int? Quantity { get; set; }
public abstract class quantity : PX.Data.BQL.BqlInt.Field<quantity> { }
#endregion

#region UnitOfMeasure
[PXDBString(250, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Unit Of Measure")]
[PXStringList(new string[] {
Constants.UOM.Each,
Constants.UOM.Set,
Constants.UOM.SquareMeter
}, new string[] {
Messages.Each,
Messages.Set,
Messages.SquareMeter
})]
public virtual string UnitOfMeasure { get; set; }
public abstract class unitOfMeasure : PX.Data.BQL.BqlInt.Field<unitOfMeasure> { }
#endregion

#region UnitCost
[PXDBDecimal()]
[PXUIField(DisplayName = "Unit Cost")]
public virtual Decimal? UnitCost { get; set; }
public abstract class unitCost : PX.Data.BQL.BqlDecimal.Field<unitCost> { }
#endregion

#region ExtCost
[PXDBDecimal()]
[PXUIField(DisplayName = "Ext Cost")]
public virtual Decimal? ExtCost { get; set; }
public abstract class extCost : PX.Data.BQL.BqlDecimal.Field<extCost> { }
#endregion

#region UnitPrice
[PXDBDecimal()]
[PXUIField(DisplayName = "Unit Price")]
public virtual Decimal? UnitPrice { get; set; }
public abstract class unitPrice : PX.Data.BQL.BqlDecimal.Field<unitPrice> { }
#endregion

#region ManualPrice
[PXDBDecimal()]
[PXUIField(DisplayName = "Manual Price")]
public virtual Decimal? ManualPrice { get; set; }
public abstract class manualPrice : PX.Data.BQL.BqlDecimal.Field<manualPrice> { }
#endregion

#region ExtPrice
[PXDBDecimal()]
[PXUIField(DisplayName = "Ext Price")]
public virtual Decimal? ExtPrice { get; set; }
public abstract class extPrice : PX.Data.BQL.BqlDecimal.Field<extPrice> { }
#endregion

#region Discount
[PXDBBool()]
[PXUIField(DisplayName = "Discount")]
public virtual bool? Discount { get; set; }
public abstract class discount : PX.Data.BQL.BqlDecimal.Field<discount> { }
#endregion

#region DiscountAmount
[PXDBDecimal()]
[PXUIField(DisplayName = "Discount Amount")]
public virtual Decimal? DiscountAmount { get; set; }
public abstract class discountAmount : PX.Data.BQL.BqlDecimal.Field<discountAmount> { }
#endregion

#region Amount
[PXDBDecimal()]
[PXUIField(DisplayName = "Amount")]
public virtual Decimal? Amount { get; set; }
public abstract class amount : PX.Data.BQL.BqlDecimal.Field<amount> { }
#endregion

#region Tstamp
[PXDBTimestamp()]
[PXUIField(DisplayName = "Tstamp")]
public virtual byte[] Tstamp { get; set; }
public abstract class tstamp : PX.Data.BQL.BqlByteArray.Field<tstamp> { }
#endregion

#region CreatedByID
[PXDBCreatedByID()]
public virtual Guid? CreatedByID { get; set; }
public abstract class createdByID : PX.Data.BQL.BqlGuid.Field<createdByID> { }
#endregion

#region CreatedByScreenID
[PXDBCreatedByScreenID()]
public virtual string CreatedByScreenID { get; set; }
public abstract class createdByScreenID : PX.Data.BQL.BqlString.Field<createdByScreenID> { }
#endregion

#region CreatedDateTime
[PXDBCreatedDateTime()]
public virtual DateTime? CreatedDateTime { get; set; }
public abstract class createdDateTime : PX.Data.BQL.BqlDateTime.Field<createdDateTime> { }
#endregion

#region LastModifiedByID
[PXDBLastModifiedByID()]
public virtual Guid? LastModifiedByID { get; set; }
public abstract class lastModifiedByID : PX.Data.BQL.BqlGuid.Field<lastModifiedByID> { }
#endregion

#region LastModifiedByScreenID
[PXDBLastModifiedByScreenID()]
public virtual string LastModifiedByScreenID { get; set; }
public abstract class lastModifiedByScreenID : PX.Data.BQL.BqlString.Field<lastModifiedByScreenID> { }
#endregion

#region LastModifiedDateTime
[PXDBLastModifiedDateTime()]
public virtual DateTime? LastModifiedDateTime { get; set; }
public abstract class lastModifiedDateTime : PX.Data.BQL.BqlDateTime.Field<lastModifiedDateTime> { }
#endregion

#region Noteid
[PXNote()]
public virtual Guid? Noteid { get; set; }
public abstract class noteid : PX.Data.BQL.BqlGuid.Field<noteid> { }
#endregion
}

 

 


   

 [PXCacheName("Sub-Contractor Quotes")]
public class PMSubConQuote : IBqlTable
{
#region Subconid
[PXDBIdentity]
[PXUIField(DisplayName = "Subconid")]
public virtual int? Subconid { get; set; }
public abstract class subconid : PX.Data.BQL.BqlInt.Field<subconid> { }
#endregion

#region SubTaskID
[PXDBInt]
[PXUIField(DisplayName = "Sub Task ID")]
[PXDefault(typeof(Current<PMSubTask.subTaskID>))]
public virtual int? SubTaskID { get; set; }
public abstract class subTaskID : PX.Data.BQL.BqlInt.Field<subTaskID> { }
#endregion

#region Active
[PXDBBool()]
[PXUIField(DisplayName = "Active")]
public virtual bool? Active { get; set; }
public abstract class active : PX.Data.BQL.BqlBool.Field<active> { }
#endregion

#region Vendor
[Vendor]
[PXUIField(DisplayName = "Vendor")]
public virtual int? Vendor { get; set; }
public abstract class vendor : PX.Data.BQL.BqlString.Field<vendor> { }
#endregion

#region Description
[PXDBString(250, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Description")]
public virtual string Description { get; set; }
public abstract class description : PX.Data.BQL.BqlString.Field<description> { }
#endregion

#region Amount
[PXDBDecimal()]
[PXUIField(DisplayName = "Amount")]
public virtual Decimal? Amount { get; set; }
public abstract class amount : PX.Data.BQL.BqlDecimal.Field<amount> { }
#endregion

#region DiscountOffered
[PXDBBool()]
[PXUIField(DisplayName = "Discount Offered")]
public virtual bool? DiscountOffered { get; set; }
public abstract class discountOffered : PX.Data.BQL.BqlBool.Field<discountOffered> { }
#endregion

#region DiscountPercentage
[PXDBDecimal()]
[PXUIField(DisplayName = "Discount Percentage")]
public virtual Decimal? DiscountPercentage { get; set; }
public abstract class discountPercentage : PX.Data.BQL.BqlDecimal.Field<discountPercentage> { }
#endregion

#region DiscountAmount
[PXDBDecimal()]
[PXUIField(DisplayName = "Discount Amount")]
public virtual Decimal? DiscountAmount { get; set; }
public abstract class discountAmount : PX.Data.BQL.BqlDecimal.Field<discountAmount> { }
#endregion

#region RebateOffered
[PXDBBool()]
[PXUIField(DisplayName = "Rebate Offered")]
public virtual bool? RebateOffered { get; set; }
public abstract class rebateOffered : PX.Data.BQL.BqlDecimal.Field<rebateOffered> { }
#endregion

#region RebatePercentage
[PXDBDecimal()]
[PXUIField(DisplayName = "Rebate Percentage")]
public virtual Decimal? RebatePercentage { get; set; }
public abstract class rebatePercentage : PX.Data.BQL.BqlDecimal.Field<rebatePercentage> { }
#endregion

#region RebateAmount
[PXDBDecimal()]
[PXUIField(DisplayName = "Rebate Amount")]
public virtual Decimal? RebateAmount { get; set; }
public abstract class rebateAmount : PX.Data.BQL.BqlDecimal.Field<rebateAmount> { }
#endregion

#region TaxCategory
[PXDBString(250, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Tax Category")]
[PXStringList(new string[] {
Constants.TaxCat.Exempt,
Constants.TaxCat.Taxable
}, new string[] {
Messages.Exempt,
Messages.Taxable
})]
public virtual string TaxCategory { get; set; }
public abstract class taxCategory : PX.Data.BQL.BqlString.Field<taxCategory> { }
#endregion

#region Tstamp
[PXDBTimestamp()]
[PXUIField(DisplayName = "Tstamp")]
public virtual byte[] Tstamp { get; set; }
public abstract class tstamp : PX.Data.BQL.BqlByteArray.Field<tstamp> { }
#endregion

#region CreatedByID
[PXDBCreatedByID()]
public virtual Guid? CreatedByID { get; set; }
public abstract class createdByID : PX.Data.BQL.BqlGuid.Field<createdByID> { }
#endregion

#region CreatedByScreenID
[PXDBCreatedByScreenID()]
public virtual string CreatedByScreenID { get; set; }
public abstract class createdByScreenID : PX.Data.BQL.BqlString.Field<createdByScreenID> { }
#endregion

#region CreatedDateTime
[PXDBCreatedDateTime()]
public virtual DateTime? CreatedDateTime { get; set; }
public abstract class createdDateTime : PX.Data.BQL.BqlDateTime.Field<createdDateTime> { }
#endregion

#region LastModifiedByID
[PXDBLastModifiedByID()]
public virtual Guid? LastModifiedByID { get; set; }
public abstract class lastModifiedByID : PX.Data.BQL.BqlGuid.Field<lastModifiedByID> { }
#endregion

#region LastModifiedByScreenID
[PXDBLastModifiedByScreenID()]
public virtual string LastModifiedByScreenID { get; set; }
public abstract class lastModifiedByScreenID : PX.Data.BQL.BqlString.Field<lastModifiedByScreenID> { }
#endregion

#region LastModifiedDateTime
[PXDBLastModifiedDateTime()]
public virtual DateTime? LastModifiedDateTime { get; set; }
public abstract class lastModifiedDateTime : PX.Data.BQL.BqlDateTime.Field<lastModifiedDateTime> { }
#endregion

#region Noteid
[PXNote()]
public virtual Guid? Noteid { get; set; }
public abstract class noteid : PX.Data.BQL.BqlGuid.Field<noteid> { }
#endregion
}

Please find the graph below:

    public class SubTaskEntry : PXGraph<SubTaskEntry>
{

public PXInsert<PMSubTask> Insert;
public PXSave<PMSubTask> Save;
public PXCancel<PMSubTask> Cancel;
public PXDelete<PMSubTask> Delete;
public PXFirst<PMSubTask> First;
public PXPrevious<PMSubTask> Previous;
public PXNext<PMSubTask> Next;
public PXLast<PMSubTask> Last;

public SelectFrom<PMSubTask>.View SubTasks;

public SelectFrom<PMBillOfQuantity>.
Where<PMBillOfQuantity.subTaskId.
IsEqual<PMSubTask.subTaskID.FromCurrent>>.View BillOfQuantity;

public SelectFrom<PMSubConQuote>.
Where<PMSubConQuote.subTaskID.
IsEqual<PMSubTask.subTaskID.FromCurrent>>.View SubConQuote;


protected void _(Events.RowUpdated<PMBillOfQuantity> e)
{
var selectedProjectID = SubTasks.Current.ProjectID;
var selectedProjectTask = SubTasks.Current.Taskid;

ProjectEntry graph = CreateInstance<ProjectEntry>();

var row = (PMBillOfQuantity)e.Row;


graph.Project.Current = graph.Project
.Search<PMProject.contractID>(selectedProjectID, "P");
PMCostBudget CB = new PMCostBudget
{
ProjectTaskID = selectedProjectTask,
AccountGroupID = 35,
InventoryID = row.InventoryId
};
CB = graph.CostBudget.Insert(CB);

CB.Qty= row.Quantity;
CB.Description = row.Description;
CB.CuryUnitRate = row.UnitPrice;

graph.CostBudget.Update(CB);


graph.Persist();
}

protected void _(Events.RowUpdated<PMSubConQuote> e)
{
var selectedProjectID = SubTasks.Current.ProjectID;
var selectedProjectTask = SubTasks.Current.Taskid;

ProjectEntry graph = CreateInstance<ProjectEntry>();

var row = (PMSubConQuote)e.Row;

graph.Project.Current = graph.Project
.Search<PMProject.contractID>(selectedProjectID, "P");
PMCostBudget CB = new PMCostBudget
{
ProjectTaskID = selectedProjectTask,
AccountGroupID = 35,
InventoryID = row.Vendor
};
CB = graph.CostBudget.Insert(CB);


CB.CuryAmount = row.Amount;
CB.Description = row.Description;

graph.CostBudget.Update(CB);


graph.Persist();
}
}


Thank you in advance


1 reply

Userlevel 6
Badge +6

Some troubleshooting steps -- I see two potential issues.

1 - Lack of key fields

You only have InventoryID defined as the unique key in the first DAC. Looking at your DACs, I think the keys should be the following:

  • PMBillOfQuantity: BillOfQuantityID only or SubTaskID and InventoryID (second option assumes the same inventory ID can’t get repeated for a given subtask)
  • PMSubConQuote: Subconid or SubTaskID and Vendor(same comment as above)

You can set IsKey=True on PXDBIdentity, if this is what you choose to do.

2 - Defaulting of SubTaskID (relation to parent row)

Is PMSubTask.subTaskID an identify field? Is the record created at the same time as the child record? Have you verified if you have a row in the database and whether the row has any missing values? If the issue is what I think, you’d see a row but with a negative ID in PMBillofQuantity.SubTaskID and PMSubConQuote.SubTaskID. You are using PXDefault to set a value in this field:

[PXDefault(typeof(Current<PMSubTask.subTaskID>))]

PXDefault is only executed when the record is inserted. At this time, PMSubTask.subTaskID does not have a valid identity value when record is first created. PXDBDefault will achieve what you want, and takes care of retrieving the value from the parent record and then updating the child rows before persisting them.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2020  Acumatica, Inc. All rights reserved