Requirement:
Client wants to receive emails after 24 hours after the BOL is uploaded by them in the IF, and every next 24 hours.
Solution:
//Search to get the IFs in which the BOL was updates, but not shipped even after 24 hours
fetchIFuploadedBOL_24hours: function(){
let itemfulfillmentSearchObj = search.create({
type: "itemfulfillment",
filters:
[
["type","anyof","ItemShip"],
"AND",
["createdfrom.type","anyof","SalesOrd"],
"AND",
["status","noneof","ItemShip:C"],
"AND",
["custbody13","is","T"],
"AND",
["mainline","is","T"],
"AND",
["shipping","is","F"],
"AND",
["taxline","is","F"],
"AND",
["cogs","is","F"],
"AND",
["shipmethod","anyof","2131"],
"AND",
["systemnotes.field","anyof","CUSTBODY13"],
"AND",
["systemnotes.newvalue","is","T"]
],
columns:
[
search.createColumn({
name: "tranid",
join: "createdFrom",
summary: "GROUP",
label: "Order ID"
}),
search.createColumn({
name: "otherrefnum",
join: "createdFrom",
summary: "GROUP",
label: "PO#"
}),
search.createColumn({
name: "tranid",
summary: "GROUP",
label: "Document Number"
}),
search.createColumn({
name: "memo",
summary: "GROUP",
label: "Memo"
}),
search.createColumn({
name: "internalid",
join: "customer",
summary: "GROUP",
label: "Customer"
}),
search.createColumn({
name: "formulanumeric",
summary: "SUM",
formula: "FLOOR((TO_DATE(TO_CHAR({today},'MM/DD/YYYY HH24:MI:SS'),'MM/DD/YYYY HH24:MI:SS')-TO_DATE(TO_CHAR({systemnotes.date},'MM/DD/YYYY HH24:MI:SS'),'MM/DD/YYYY HH24:MI:SS'))*24)",
label: "Formula (Numeric)"
}),
search.createColumn({
name: "date",
join: "systemNotes",
summary: "MIN",
label: "Date"
}),
search.createColumn({
name: "internalid",
summary: "GROUP",
label: "Internal ID"
})
]
});
let ifDetailArray = [];
let searchResultCount = itemfulfillmentSearchObj.runPaged().count;
if (searchResultCount > 0) {
itemfulfillmentSearchObj.run().each(function (result) {
let ifDetailObject = {}
ifDetailObject.ifDocNum = result.getValue({
name: "tranid",
summary: "GROUP",
label: "Document Number"
})
ifDetailObject.soDocNum = result.getValue({
name: "tranid",
join: "createdFrom",
summary: "GROUP",
label: "Order ID"
})
ifDetailObject.po = result.getValue({
name: "otherrefnum",
join: "createdFrom",
summary: "GROUP",
label: "PO#"
})
ifDetailObject.customerId = result.getValue({
name: "internalid",
join: "customer",
summary: "GROUP",
label: "Customer"
})
ifDetailObject.internalId = result.getValue({
name: "internalid",
summary: "GROUP",
label: "Internal ID"
})
ifDetailObject.memoData = result.getValue({name: "memo",summary: "GROUP", label: "Memo"})
ifDetailObject.sysDate = result.getValue({
name: "formulanumeric",
summary: "SUM",
formula: "FLOOR((TO_DATE(TO_CHAR({today},'MM/DD/YYYY HH24:MI:SS'),'MM/DD/YYYY HH24:MI:SS')-TO_DATE(TO_CHAR({systemnotes.date},'MM/DD/YYYY HH24:MI:SS'),'MM/DD/YYYY HH24:MI:SS'))*24)",
label: "Formula (Numeric)"
})
ifDetailObject.dueTime = 24
ifDetailArray.push(ifDetailObject)
return true;
});
}
return ifDetailArray
}
//code in reduce stage of map/reduce script
let results = JSON.parse(reduceContext.values)
// get the customer id, item line location
let customer = results.customerId
let locationId = main.getItemLineLocation(results.internalId)
let dueTime = results.dueTime
let diffInHours = results.sysDate
if ( main.checkForParameter(diffInHours) && diffInHours % 24 == 0) {
//send email
main.sendEmail(results, customer, locationId[0])
}
//function to send email
sendEmail: function (results, customer, locationId){
let recipient = ['logist***@corp***.com']
if (locationId == 1 || locationId == 5) {
recipient.push('CorpDesign***-MIA@cran***.com')
}
else if (locationId == 6 || locationId == 4) {
recipient.push('CorpDe***-DFW@cran***.com')
}
let author = 1659;
let docNum = main.checkForParameter(results.po) ? results.soDocNum +"/"+ results.ifDocNum +"/"+ results.po : results.soDocNum +"/"+ results.ifDocNum
let docNumBody = main.checkForParameter(results.memoData) ? docNum + " (" + results.memoData +")" : docNum
let subject = "The BOL for "+ docNum + " has been uploaded for over 24 hours and need to ship immediately!"
let body = "The BOL for " + docNumBody + " has been uploaded for over 24 hours and need to ship immediately!<br>"+
"<b><u>Freight Broker</u></b>: You are receiving this message because the order listed above hasn’t been picked up from our warehouse, please contact carrier and have this shipment pickup today!<br>"+
"<b><u>Warehouse</u></b>: If this order is no longer on your dock then you MUST mark it as shipped immediately, otherwise both you and our freight broker will keep receiving this notice until the order has been picked up and marked as SHIPPED!<br><br>"+
"Thank You."
email.send({
author: author,
recipients: recipient,
subject: subject,
body: body,
relatedRecords: {
entityId: recipient,
}
});
}