Auto-approval of purchase order workflow for net amount field value same or less

You can get the latest PurchTableHistory by using findLatest method in that table. By using PurchTableHistory you can get the PurchLineHistory records (have a look at PurchLineDocument class - calcHistoryInvoiceAmount method).
Finally compare the PurchLineHistory.LineAmount and purchLine.LineAmount (you can relate both tables by using InventTransId field)

Hi Kranthi,
I am not able to see any method like “findLatest” in PurchTableHistory.
Can you give me the sample code.

You may need to have a method that return true/false and use that in your workflow condition.
The below is the sample code, (you can improve it)

private boolean isPurchLineAmountIncreased(CompanyId _companyId,TableId _tableId, RecId _recId)
{
PurchLineHistory purchLineHistory;
PurchTableVersion purchTableVersion;
boolean ret;
PurchLine purchLine;

this.getPurchTable(_recId);

purchTableVersion = purchTableVersion::findLatest(purchTable.PurchId, purchTable.dataAreaId);

while select purchLine
where purchLine.PurchId == purchTable.PurchId
&& !purchLine.IsDeleted
{
purchLineHistory = PurchLineHistory::find(purchLine, purchTableVersion.VersionDateTime);
if (purchLineHistory.RecId &&
purchLine.LineAmount > purchLineHistory.LineAmount)
{
ret = true;
break;
}
}
return ret;
}

Hi Kranthi,
If i use method to return boolean value then workflow stopped error is coming.
I hope method starts with parm only it will run.
I have written code like this.I am having two lines.If i increase the first line net amount and its taking second and it go for manual approval.
public PurchLineAmount parmLineAmount(CompanyId _companyId,TableId _tableId, RecId _recId)
{
PurchLineAllVersions PurchLineAllVersions;
PurchTableHistory PurchTableHistory;
PurchLineHistory PurchLineHistory;
PurchLineAmount oldlineamount,PurchLineAmountret;
purchTableVersion purchTableVersion;
PurchLine purchLine;
;
this.getPurchTable(_recId);

purchTableVersion = purchTableVersion::findLatest(purchTable.PurchId, purchTable.dataAreaId);

while select purchLine where purchLine.PurchId == purchTable.PurchId
{
oldlineamount = PurchLineHistory::find(purchLine, purchTableVersion.VersionDateTime).LineAmount;

if( purchLine.LineAmount <= oldlineamount)
{
PurchLineAmountret = purchLine.LineAmount;
}
else
{
PurchLineAmountret = oldlineamount;
}
}
return PurchLineAmountret;
}

Am I doing anything wrong.Guide me to get the solution.

what error you are getting? How did you setup the workflow by using this field?

Hi Kranthi,

while running the purchase order workflow getting error in bottom of the workflow grid.

Stopped (error):

This is the Workflow Expression. Purchaseorder.NetAmount placeholder is displayed from the Customized method in “PurchTableDocument”.

Expression.JPG

If you write the method to return the boolean value (as i suggested), then you should use that method in the workflow condition.
Example : PurchaseOrders.isPurchLineAmountIncreased need to be used in workflow and you need to check whether it is true/false.

Hi Kranthi,
I will check and update you soon.

Hi Kranthi,
Thanks for your reply.
I have created two parm methods to return the new net amount value and old net amount value.
I have added this two methods in the workflow expression.
I have not selected the net amount field in the purchasing policy.