Jeremy Eda
06/22/2020, 5:27 PMSandii
06/22/2020, 5:41 PMJeremy Eda
06/22/2020, 5:43 PMJeremy Eda
06/22/2020, 5:43 PMbattk
06/22/2020, 5:44 PMbattk
06/22/2020, 5:44 PMJeremy Eda
06/22/2020, 5:45 PMJeremy Eda
06/22/2020, 5:46 PMbattk
06/22/2020, 5:46 PMJeremy Eda
06/22/2020, 5:47 PMnlapiLogExecution("DEBUG","STARTING PRE-DESIGNED GRAPHIC AUTOMATION");
function main(request, response)
{
nlapiLogExecution('DEBUG','Getting Request');
var s3Id = request.getParameter('s3RecordId');
var item = request.getParameter('lineItem');
//var context = nlapiGetContext();
//var req_param = context.request.parameters;
nlapiLogExecution('DEBUG','Loading Amazon S3 Record');
var s3Record = nlapiLoadRecord('customrecord_sc_s3_files', s3Id);
nlapiLogExecution('DEBUG','S3 Record Id', s3Id);
//var s3Record = nlapiLoadRecord('customrecord_sc_s3_files', req_param.s3RecordId);
//nlapiLogExecution('DEBUG','S3 Record Id', req_param.s3RecordId);
//Block Quick Proof Email Checkbox
nlapiLogExecution('DEBUG','Blocking quickproof email');
s3Record.setFieldValue('custrecord_blockquickproofemail', 'T');
//Set File Uploaded by Customer Field
nlapiLogExecution('DEBUG','Loading Item Record');
var itemRecord = nlapiLoadRecord('assemblyitem', item);
nlapiLogExecution('DEBUG','Line Item', item);
//var itemRecord = nlapiLoadRecord('assemblyitem', req_param.lineItem);
//nlapiLogExecution('DEBUG','Line Item', req_param.lineItem);
nlapiLogExecution('DEBUG','Setting File Uploaded By Customer Field');
var fileUploadedByCustomer = itemRecord.getFieldValue('custitem_s3_pd_graphic_link');
s3Record.setFieldValue('custrecord_fileuploadedbycustomer', fileUploadedByCustomer);
nlapiLogExecution('DEBUG','File Uploaded By Customer', fileUploadedByCustomer);
nlapiSubmitRecord(s3Record);
}
Jeremy Eda
06/22/2020, 5:48 PMJeremy Eda
06/22/2020, 5:48 PMbattk
06/22/2020, 6:19 PMJeremy Eda
06/22/2020, 6:20 PMbattk
06/22/2020, 6:21 PMJeremy Eda
06/22/2020, 6:25 PMfunction createRecords(type) {
if (type == 'create' || type == 'edit') {
var salesOrder = nlapiGetNewRecord(), lines = getSalesOrderLines(salesOrder);
try {
var currOrderStat = salesOrder.getFieldValue('custbody_orderstatus');
var customerSource = salesOrder.getFieldValue('custbody_f3_source');
if (customerSource == "WS Display - beta"){
dLog('source is not wsdisplay, signmall or manual. exit', ' source is not wsdisplay, signmall or manual. exit');
return;
}
if (!inArray(currOrderStat, arrOrderStat)) {
var statText = salesOrder.getFieldText('custbody_orderstatus');
dLog('beforeLoad_showReprints', statText + ' Order status | no need to execute. exit script.');
return;
}
} catch (e) {
nlapiLogExecution('ERROR', 'Record not created');
}
if (type == 'create') {
dLog('attempting to create file records', 'attempting to create S3 and GA records');
lines = createGraphicApprovalRecords(lines, salesOrder);
createFileRecords(lines, salesOrder);
} else {
nlapiLogExecution('DEBUG', 'Calling updateFileRecords');
updateFileRecords(lines, salesOrder);
}
}
}
Jeremy Eda
06/22/2020, 6:25 PMbattk
06/22/2020, 6:27 PMJeremy Eda
06/22/2020, 6:28 PMfunction createGraphicApprovalRecords(lines, salesOrder) {
var customerId = salesOrder.getFieldValue('entity'), status = GRAPHIC_APPROVAL_STATUS, salesOrderId = salesOrder.getId();
nlapiLogExecution('DEBUG','In createGraphicApprovalRecords');
_.each(lines, function(line) {
var record = nlapiCreateRecord('customrecord_sc_graphic_approval');
record.setFieldValue('custrecord_sc_ga_customer', customerId);
record.setFieldValue('custrecord_sc_ga_status', status);
record.setFieldValue('custrecord_sc_ga_sales_order', salesOrderId);
record.setFieldValue('custrecord_sc_ga_line_identifier', line.identifier);
record.setFieldValue('custrecord_sc_ga_item', line.item);
record.setFieldValue('custrecord_sc_ga_item_quantity', line.quantity);
record.setFieldValue('custrecord_sc_ga_location', line.location);
//CHECK FOR PRE-DESIGNED GRAPHIC UPON ORDER CREATION
nlapiLogExecution('DEBUG','In CreateGA Line.Order Detail: ', line.orderDetail);
//If Order Detail is "Pre-Designed Graphic" set Graphic Approval field: Status to "Approved", Internal ID: 1
if(line.orderDetail == "Pre-Designed Graphic")
{
record.setFieldValue('custrecord_sc_ga_status', GRAPHIC_APPROVED);
nlapiLogExecution('DEBUG','Graphic Status', 'Pre-Designed, Setting status to Approved');
}
line.grapphicApproval = nlapiSubmitRecord(record);
//Creates link to graphic approval page for designer to upload files in the future
var url = nlapiResolveURL('SUITELET', 'customscript_sc_ga_approval_designer', 'customdeploy_sc_ga_approval_designer', false), id = line.grapphicApproval;
record = nlapiLoadRecord('customrecord_sc_graphic_approval', id);
record.setFieldValue('custrecord_sc_ga_approval_link', url + '&id=' + id);
nlapiSubmitRecord(record);
nlapiLogExecution('ERROR', 'graphic approval record created');
});
return lines;
}
Jeremy Eda
06/22/2020, 6:28 PMJeremy Eda
06/22/2020, 6:28 PMJeremy Eda
06/22/2020, 6:29 PMbattk
06/22/2020, 6:29 PMbattk
06/22/2020, 6:30 PMJeremy Eda
06/22/2020, 6:31 PMJeremy Eda
06/22/2020, 6:32 PMJeremy Eda
06/22/2020, 6:32 PMJeremy Eda
06/22/2020, 6:32 PMfunction createFileRecords(lines, salesOrderId) {
nlapiLogExecution('DEBUG','In createFileRecords');
_.each(lines, function(line) {
var record = nlapiCreateRecord('customrecord_sc_s3_files');
record.setFieldValue('custrecord_sc_amazon_sales_order_id', salesOrderId.getId());
record.setFieldValue('custrecord_sc_amazon_sales_order', salesOrderId.getId());
record.setFieldValue('custrecord_sc_s3_line', line.identifier);
record.setFieldValue('custrecord_sc_line_item', line.item);
record.setFieldValue('custrecord_sc_uploaded_by_customer', 'T');
record.setFieldValue('custrecord_sc_s3_graphic_approval', line.grapphicApproval);
//IF ORDER DETAIL IS PRE-DESIGNED GRAPHIC
if(line.orderDetail == "Pre-Designed Graphic")
{
//redirect to Pre-Designed Graphic suitelet
nlapiLogExecution('DEBUG', 'Item is Pre-Designed Graphic: REDIRECTING TO PRE-DESIGNED GRAPHIC AUTOMATION SUITELET');
nlapiSubmitRecord(record);
var params = {"s3RecordId": record.getId(),
"lineItem": line.item};
nlapiSetRedirectURL('SUITELET','customscript_tflow_pd_graphic_automation','customdeploy_tflow_pd_graphic_automation', null, params);
nlapiLogExecution('DEBUG', 'Returning from redirect');
//nlapiLogExecution('DEBUG','Blocking quickproof email');
//Block Quickproof Email
//record.setFieldValue('custrecord_blockquickproofemail', 'T');
}
else
{
nlapiSubmitRecord(record);
}
nlapiLogExecution('ERROR', 'file records created');
});
}
battk
06/22/2020, 6:35 PMbattk
06/22/2020, 6:37 PMItem is Pre-Designed Graphic: REDIRECTING TO PRE-DESIGNED GRAPHIC AUTOMATION SUITELET
log in the script logs?Jeremy Eda
06/22/2020, 6:38 PMJeremy Eda
06/22/2020, 6:38 PMbattk
06/22/2020, 6:38 PMJeremy Eda
06/22/2020, 6:38 PMbattk
06/22/2020, 6:40 PMbattk
06/22/2020, 6:40 PMbattk
06/22/2020, 6:41 PMbattk
06/22/2020, 6:42 PMJeremy Eda
06/22/2020, 6:44 PMJeremy Eda
06/22/2020, 6:55 PMJeremy Eda
06/22/2020, 6:55 PMbattk
06/22/2020, 6:56 PMJeremy Eda
06/22/2020, 6:59 PM