I would like to get code that will pull in unresolved orders (on admin hold) within the last 24 months. I am very new to MEL code I have been able to pull in all unresolved orders using {ORDERS_PRIOR('list','T')} but unsure of where to go from here to add the within last 24 months. HELP! 🙂
I would pull a delimited list in to an array. Then you can loop through the array and add the orders to a string based on whatever conditions you set.
This function will return an array with each element being a separate order.
Getfield(ORDERS_PRIOR(“delimited“,”T”),”|”,””)
Something like this might get you close:
{!fn pa_get_unres_ords_24m(ords){
if ords == "" then return "" else "" endif
local arrOrd, n,i,strTemp ="", arrTemp, result=""
arrOrd=getfield(ords, "|","")
for n=1, n<=size(arrOrd), n=n+1
do
arrOrd[n]=getfield(arrOrd[n], "^","")
if arrOrd[n][20] == "H" then
if strTemp <> "" then strTemp=strTemp+"|"+arrOrd[n][1] + "^" + arrOrd[n][3] +"^"+ arrOrd[n][4] else
strTemp=arrOrd[n][1] + "^" + arrOrd[n][3] + "^"+arrOrd[n][4]
endif
endif
endfor
if strTemp <> "" then arrTemp=getfield(strTemp, "|","") else return "" endif
for i=1, i<=size(arrTemp), i=i+1
do
arrTemp[i]=getfield(arrTemp[i],"^","")
if durationdays(arrTemp[i][3],str(._todaysdate)) >0 then
if result <> "" then result=result + hret + arrTemp[i][1] + " " + arrTemp[i][2] + arrTemp[i][3] else
result= arrTemp[i][1] + " " + arrTemp[i][2] + arrTemp[i][3]
endif
endif
endfor
return result}}
Here's the revised fn after confirming with aweymouth that it returned what was requested in case others can use it:
{!fn pa_get_unres_ords_24m(ords){
if ords == "" then return "" else "" endif
local arrOrd, n, result=""
arrOrd=getfield(ords, "|","")
for n=1, n<=size(arrOrd), n=n+1
do
arrOrd[n]=getfield(arrOrd[n], "^","")
if arrOrd[n][20] == "H" then
if durationdays(arrOrd[n][4], str(._todaysdate)) > 0 and durationdays(arrOrd[n][4], str(._todaysdate)) < 731 then
if result <> "" then result=result + hret + "Order: " + arrOrd[n][1] + " Code: " + arrOrd[n][3] +" Date: "+ arrOrd[n][4] else
result ="Order: " + arrOrd[n][1] + " Code: " + arrOrd[n][3] +" Date: "+ arrOrd[n][4]
endif
endif
endif
endfor
return result}
}