How to take minimum date in purchase order

Hi Experts,

I have one requirement to solve. I want to take minimum date from purchase order line.

for e.g:

PO itemid Date

PO1 I1 1/6/2018

PO2 I1 5/6/2018

PO3 I1 5/6/2018

PO4 I3 10/6/2018

PO5 I1 15/6/2018

PO6 I4 20/6/2018

In this example, i want to take only minimum date purchase order. in above example, one item have multiple purchase order and different date also. In that i want take purchase order which contain minimum date. how to solve this?

Advance in thanks and Regards,

AXDeveloper

You can find the minimum date using below query

select Firstonly * from purchLine

where purchLine.purchId==‘XYZ’

Order by purchLine.Date asc

I tried this code - check this code

static void MinDate(Args _args)
{
Employee emp;
;
select minof(JoiningDate) from emp;

info(strfmt(’%1’, emp.JoiningDate));
}

it’s working properly. but above code throwing syntax error.

Thanks in advance and regards,

AXDeveloper

Can you confirm the name of the Date field of purch line. I will share the actual query with you.

Sorry It’s InventQuarantineOrder table and the field is QuarantineDate.

public static server void jobs(Args _args)
{
InventQuarantineOrder objInventQuarantineOrder ;
InventQualityOrderTable objInventQualityOrderTable;

select firstOnly * from objInventQuarantineOrder
join objInventQualityOrderTable
order by objInventQuarantineOrder.QuarantineDate asc
where objInventQualityOrderTable.ReferenceType==4
&& objInventQualityOrderTable.InventRefId==objInventQuarantineOrder.QuarantineId
&& objInventQuarantineOrder.QuarantineId==“XYZ”;
}

Thanks for reply sheikh. One more query , I want to select purchid from purch table using date range .

for eg:

I want to retrieve particular month purchase order (date - 1/6/2018 to 30/6/2018).

how to do get ?

Advance in thanks and regards,

AXDeveloper

Dear AxDeveloper

You can use the below demo code,you have to perform little changes like remove firstonly10 and change the min and max date with your actual datetime.

Please mark this answer suggested if 1st solution work for you.

static void Job2(Args _args)
{

PurchTable purchTable;

while select firstOnly10 purchTable
where purchTable.createdDateTime >= DateTimeUtil::minValue() && purchTable.createdDateTime <= DateTimeUtil::maxValue()
{
info(purchTable.PurchId);
}

}

One more question sheikh, how to pass date value, that means i want to hard code a from_date and to_date to get a purchid.

like - (15/6/2018) to (0/6/2018) need purchid with in this date.

Thanks in advance and regards,

AXDeveloper

You can pass as parameter to the query.

static void Job2(Args _args)
{

DateTime startDate,EndDate;

PurchTable purchTable;

startDate=DateTimeUtil::minValue() ;

EndDate=DateTimeUtil::maxValue();

while select firstOnly10 purchTable
where purchTable.createdDateTime >= startDate && purchTable.createdDateTime <=EndDate
{
info(purchTable.PurchId);
}

}

it’s throwing error like datetime is not declared , i tried through jobs.