How to make Unit Price(PurchPrice) editable in Purchase requisition lines in Dynamics 365 for finance and operations
The only way to make it possible is by extending the purchreqline table method and using Chain of Command(CoC)
The following code will make you achieve the task:
[ExtensionOf(tablestr(PurchReqLine))]
final class PurchReqLine_Extension
{
public boolean allowFieldEdit(FieldId _fieldId, boolean _isUserTaskApprovalOwner )
{
boolean allowEdit= false;
allowEdit = next allowFieldEdit(_fieldId,_isUserTaskApprovalOwner);
{
if (_isUserTaskApprovalOwner && (this.RequisitionStatus == PurchReqRequisitionStatus::Draft ||
this.RequisitionStatus == PurchReqRequisitionStatus::InReview ||
this.RequisitionStatus == PurchReqRequisitionStatus::Rejected))
{
switch (_fieldId)
{
case fieldNum(PurchReqLine,PurchPrice):
if (this.LineType == PurchReqLineType::Item || this.LineType == PurchReqLineType::Category)
{
allowEdit = true;
}
break;
case fieldNum(PurchReqLine, PurchQty):
if (this.LineType == PurchReqLineType::Item || this.LineType == PurchReqLineType::Category)
{
allowEdit = true;
}
break;
case fieldNum(PurchReqLine, LineAmount):
if (this.LineType == PurchReqLineType::Item || this.LineType == PurchReqLineType::Category)
{
allowEdit = false;
}
break;
}
}
}
Return allowEdit;
}
}
Note:I have added code to ensure that the quantity(PurchQty) field remains editable and the net amount
field(LineAmount) is not editable.