content
stringlengths
253
286k
index
int64
4
1.23k
secrets
stringlengths
64
1.84k
has_secrets
bool
1 class
number_secrets
int64
1
20
new_content
stringlengths
239
286k
modified
bool
1 class
references
stringlengths
254
286k
/** * @NApiVersion 2.x * @NScriptType ScheduledScript * @NAmdConfig ./custom_modules_config.json * * Module Description * * @Author: ankith.ravindran * @Date: 2018-09-19 13:20:56 * @Last Modified by: Anesu Chakaingesu * @Last Modified time: 2020-04-30 14:56:03 */ define(['N/ui/serverWidget', 'N/email', 'N/runtime', 'N/search', 'N/record', 'N/http', 'N/log', 'N/redirect', 'N/task', 'moment2', 'N/format'], function(ui, email, runtime, search, record, http, log, redirect, task, moment, format) { // log.debug({ // title: 'moment Defined', // details: JSON.stringify(moment) // }); var days_of_week = []; days_of_week[0] = 0; days_of_week[1] = 'custrecord_service_freq_stop.custrecord_service_freq_day_mon'; days_of_week[2] = 'custrecord_service_freq_stop.custrecord_service_freq_day_tue'; days_of_week[3] = 'custrecord_service_freq_stop.custrecord_service_freq_day_wed'; days_of_week[4] = 'custrecord_service_freq_stop.custrecord_service_freq_day_thu'; days_of_week[5] = 'custrecord_service_freq_stop.custrecord_service_freq_day_fri'; days_of_week[6] = 6; var days_of_week2 = []; days_of_week2[0] = 0; days_of_week2[1] = 'custrecord_service_freq_day_mon'; days_of_week2[2] = 'custrecord_service_freq_day_tue'; days_of_week2[3] = 'custrecord_service_freq_day_wed'; days_of_week2[4] = 'custrecord_service_freq_day_thu'; days_of_week2[5] = 'custrecord_service_freq_day_fri'; days_of_week2[6] = 6; var usage_threshold = 200; //20 var usage_threshold_invoice = 1000; //1000 var adhoc_inv_deploy = 'customdeploy2'; var prev_inv_deploy = null; var ctx = runtime.getCurrentScript(); var date_of_week; function main(){ var day = moment().utc().day(); var date = moment().utc().add(1, 'days').date(); var month = moment().utc().month(); var year = moment().utc().year(); var startDate = moment([year, month]); var endDate = moment(startDate).endOf('month').date(); if(moment().utc().date() == endDate){ date_of_week = date + '/' + (month + 2) + '/' + year; } else { date_of_week = date + '/' + (month + 1) + '/' + year; } // date_of_week = date + '/' + (month + 1) + '/' + year; log.audit({ title: 'moment().utc()', details: moment().utc() }) log.audit({ title: 'day', details: day }) log.audit({ title: 'original date', details: moment().utc().date() }) log.audit({ title: 'date', details: date }) log.audit({ title: 'Last Day of Month', details: endDate }) log.audit({ title: 'month', details: month }) log.audit({ title: 'year', details: year }) log.audit({ title: 'date_of_week', details: date_of_week }) log.audit({ title: 'days_of_week[day + 1]', details: days_of_week[day + 1] }); log.audit({ title: 'days_of_week[day]', details: days_of_week[day] }); log.audit({ title: 'prev_deployment', details: ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }) }) if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }))) { prev_inv_deploy = ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }) } else { prev_inv_deploy = ctx.deploymentId; } var zeeSearch = search.load({ type: 'partner', id: 'customsearch_rp_zee_no_job_created_2_2' }); var resultZee = zeeSearch.run(); //.getRange({ start: 0, end: 1}) // log.audit({ // title: 'searchResultZee', // details: resultZee // }) resultZee.each(function(searchResultZee) { var zee_id = searchResultZee.getValue({ name: "internalid"}); // var zee_id = 215 // Alexandria // var zee_id = 5386 // Arncliffe // var zee_id = 621451 // Gold Coast // var zee_id = 780481 // TEST - ACT // var zee_id = 779884 // TEST - NSW // var zee_id = 626844 // TEST - QLD // var zee_id = 626428 // TEST - VIC // var zee_id = 626845 // TEST - WA var zee_name = searchResultZee.getValue({ name: "entityid"}); log.debug({ title: 'Zee Name', details: zee_name }); //SEARCH: RP - Service Leg Frequency - All - Create App Jobs // if (day != 0 && day != 6){ var runPlanSearch; new_day = day + 1; log.debug({ title: 'day', details: 'New Day' + new_day + 'Old Day' + day }); switch (new_day){ case 1: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_mon'}); break; case 2: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_tue'}); break; case 3: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_wed'}); break; case 4: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_thu'}); break; case 5: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_fri'}); break; } log.debug({ title: 'runPlanSearch', details: runPlanSearch }) // } // var runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_jo_2'}); // customsearch_rp_leg_freq_create_app_jo_2 or customsearch_rp_leg_freq_create_app_jobs // log.debug({ // title: 'days_of_week[day]', // details: days_of_week[day] // }); // log.debug({ // title: 'service_leg_customer', // details: service_leg_customer // }); if (day != 0 && day != 6) { var filterExpression = []; var filterExpression = runPlanSearch.filterExpression; filterExpression.push('AND'); filterExpression.push([ [days_of_week[day + 1], search.Operator.IS , 'T'], // customer id "OR", ["custrecord_service_freq_stop.custrecord_service_freq_day_adhoc", search.Operator.IS , 'T'] ]); filterExpression.push("AND", ["isinactive", search.Operator.IS , "F"]); filterExpression.push("AND", ["custrecord_service_leg_customer.partner", search.Operator.IS , zee_id]); filterExpression.push("AND", ["custrecord_service_leg_customer.status", search.Operator.ANYOF, "32", "13"]); filterExpression.push("AND", ["custrecord_service_leg_service.isinactive", search.Operator.IS , "F"]); filterExpression.push("AND", ["custrecord_service_freq_stop.internalid", search.Operator.NONEOF, "@NONE@"]); filterExpression.push("AND", [ ["formulatext: CASE WHEN TO_CHAR({custrecord_service_leg_closing_date}, 'DD/MM/YYYY') <= TO_CHAR(SYSDATE, 'DD/MM/YYYY') THEN 'T' ELSE 'F' END", search.Operator.IS , "F"], "AND", ["formulatext: CASE WHEN TO_CHAR({custrecord_service_leg_opening_date}, 'DD/MM/YYYY') > TO_CHAR(SYSDATE, 'DD/MM/YYYY') THEN 'T' ELSE 'F' END", search.Operator.IS, "F"] ]); filterExpression.push("AND", ["custrecord_app_ser_leg_daily_job_create", search.Operator.ANYOF, "2", "@NONE@"]); // runPlanSearch.filterExpression = filterExpression; } log.debug({ title: 'filterExpression', details: runPlanSearch.filterExpression }); var resultRunPlan = runPlanSearch.run(); // var runPlanResult = resultRunPlan.getResults() // log.debug({ // title: 'Length', // details: runPlanResult.length // }) if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_old_service_id_create_app'}))) { var old_service_id = ctx.getParameter({ name: 'custscript_rp_old_service_id_create_app'}); } else { var old_service_id; } if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_app_job_group_id_create_app'}))) { var app_job_group_id2 = ctx.getParameter({ name: 'custscript_rp_app_job_group_id_create_app'}); } else { var app_job_group_id2; } var count = 0; var exit = false; resultRunPlan.each(function(searchResult) { var service_leg_id = searchResult.getValue({ name: "internalid", join: null, summary: search.Summary.GROUP}); var service_leg_name = searchResult.getValue({ name: "name", join: null, summary: search.Summary.GROUP}); var service_leg_zee = searchResult.getValue({ name: "custrecord_service_leg_franchisee", join: null, summary: search.Summary.GROUP}); var service_leg_customer = searchResult.getValue({ name: "custrecord_service_leg_customer", join: null, summary: search.Summary.GROUP}); var service_leg_customer_text = searchResult.getText({ name: "custrecord_service_leg_customer", join: null, summary: search.Summary.GROUP}); var service_id = searchResult.getValue({ name: "internalid", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_leg_service = searchResult.getValue({ name: "custrecord_service_leg_service", join: null, summary: search.Summary.GROUP}); var service_leg_service_text = searchResult.getText({ name: "custrecord_service_leg_service", join: null, summary: search.Summary.GROUP}); var service_price = searchResult.getValue({ name: "custrecord_service_price", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_cat = searchResult.getValue({ name: "custrecord_service_category", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_leg_no = searchResult.getValue({ name: "custrecord_service_leg_number", join: null, summary: search.Summary.GROUP}); var service_leg_ncl = searchResult.getValue({ name: "custrecord_service_leg_non_cust_location", join: null, summary: search.Summary.GROUP}); var service_leg_addr = searchResult.getValue({ name: "custrecord_service_leg_addr", join: null, summary: search.Summary.GROUP}); var service_leg_addr_postal = searchResult.getValue({ name: "custrecord_service_leg_addr_postal", join: null, summary: search.Summary.GROUP}); var service_leg_addr_subdwelling = searchResult.getValue({ name: "custrecord_service_leg_addr_subdwelling", join: null, summary: search.Summary.GROUP}); var service_leg_addr_st_num = searchResult.getValue({ name: "custrecord_service_leg_addr_st_num_name", join: null, summary: search.Summary.GROUP}); var service_leg_addr_suburb = searchResult.getValue({ name: "custrecord_service_leg_addr_suburb", join: null, summary: search.Summary.GROUP}); var service_leg_addr_state = searchResult.getValue({ name: "custrecord_service_leg_addr_state", join: null, summary: search.Summary.GROUP}); var service_leg_addr_postcode = searchResult.getValue({ name: "custrecord_service_leg_addr_postcode", join: null, summary: search.Summary.GROUP}); var service_leg_addr_lat = searchResult.getValue({ name: "custrecord_service_leg_addr_lat", join: null, summary: search.Summary.GROUP}); var service_leg_addr_lon = searchResult.getValue({ name: "custrecord_service_leg_addr_lon", join: null, summary: search.Summary.GROUP}); var service_leg_type = searchResult.getValue({ name: "custrecord_service_leg_type", join: null, summary: search.Summary.GROUP}); var service_leg_duration = searchResult.getValue({ name: "custrecord_service_leg_duration", join: null, summary: search.Summary.GROUP}); var service_leg_notes = searchResult.getValue({ name: "custrecord_service_leg_notes", join: null, summary: search.Summary.GROUP}); var service_leg_location_type = searchResult.getValue({ name: "custrecord_service_leg_location_type", join: null, summary: search.Summary.GROUP}); var service_leg_transfer_type = searchResult.getValue({ name: "custrecord_service_leg_trf_type", join: null, summary: search.Summary.GROUP}); var service_leg_transfer_linked_stop = searchResult.getValue({ name: "custrecord_service_leg_trf_linked_stop", join: null, summary: search.Summary.GROUP}); var service_freq_id = searchResult.getValue({ name: "internalid", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_mon = searchResult.getValue({ name: "custrecord_service_freq_day_mon", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_tue = searchResult.getValue({ name: "custrecord_service_freq_day_tue", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_wed = searchResult.getValue({ name: "custrecord_service_freq_day_wed", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_thu = searchResult.getValue({ name: "custrecord_service_freq_day_thu", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_fri = searchResult.getValue({ name: "custrecord_service_freq_day_fri", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_adhoc = searchResult.getValue({ name: "custrecord_service_freq_day_adhoc", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_current = searchResult.getValue({ name: "custrecord_service_freq_time_current", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_start = searchResult.getValue({ name: "custrecord_service_freq_time_start", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_end = searchResult.getValue({ name: "custrecord_service_freq_time_end", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_run_plan_id = searchResult.getValue({ name: "custrecord_service_freq_run_plan", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_operator = searchResult.getValue({ name: "custrecord_service_freq_operator", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_zee = searchResult.getValue({ name: "custrecord_service_freq_franchisee", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_multiple_operators = searchResult.getValue({ name: "custrecord_multiple_operators", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var street_no_name = null; log.debug({ title: 'service_leg_id', details: service_leg_id }); try { // statements if (!isNullorEmpty(service_freq_run_plan_id)) { log.debug({ title: 'service_freq_run_plan_id', details: service_freq_run_plan_id }) var run_plan_record = record.load({ id: service_freq_run_plan_id, type: 'customrecord_run_plan' }) var run_plan_inactive = run_plan_record.getValue({ fieldId: 'isinactive'}); log.debug({ title: 'run_plan_inactive ?', details: run_plan_inactive }) var serviceLegRecord = record.load({ type: 'customrecord_service_freq', id: service_freq_id }); var weekOfDay = serviceLegRecord.getValue({ fieldId: days_of_week2[day + 1]}); log.debug({ title: 'weekOfDay', details: weekOfDay }) if (weekOfDay == false && service_freq_adhoc == false) { } else { if (run_plan_inactive == false) { log.audit({ title: 'Run Plan Inactive = False' }); if (isNullorEmpty(service_leg_addr_subdwelling) && !isNullorEmpty(service_leg_addr_st_num)) { street_no_name = service_leg_addr_st_num; } else if (!isNullorEmpty(service_leg_addr_subdwelling) && isNullorEmpty(service_leg_addr_st_num)) { street_no_name = service_leg_addr_subdwelling; } else { street_no_name = service_leg_addr_subdwelling + ', ' + service_leg_addr_st_num; } service_leg_addr_st_num = street_no_name; if (old_service_id != service_id) { var usage_loopstart_cust = ctx.getRemainingUsage(); log.debug({ title: 'usage_loopstart_cust', details: usage_loopstart_cust }) log.debug({ title: 'usage_threshold', details: usage_threshold }) if (usage_loopstart_cust < usage_threshold) { var params = { custscript_rp_prev_deployment_create_app: ctx.deploymentId, custscript_rp_old_service_id_create_app: old_service_id, custscript_rp_app_job_group_id_create_app: app_job_group_id2 } reschedule = task.create({ taskType: task.TaskType.SCHEDULED_SCRIPT, scriptId: 'customscript_ss_create_app_jobs_2', deploymentId: 'customdeploy_ss_create_app_jobs_2', params: params }); log.audit({​​​​​ title: 'Reschedule Return - IN LOOP' }); var rescheduled = reschedule.submit(); // if (task.checkStatus({​​​​​ taskId: reschedule}​​​​​) == false) {​​​​​ // exit = true; // return false; // }​​​​​ } createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id2, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators); var service_leg_record = record.load({ id: service_leg_id, type: 'customrecord_service_leg' }) service_leg_record.setValue({ fieldId: 'custrecord_app_ser_leg_daily_job_create', value: 1}); var service = service_leg_record.save(); log.audit({ title: 'Service Leg - Saved', details: service }) app_job_group_id2 = createAppJobGroup(service_leg_service_text, service_leg_customer, service_leg_zee, service_id); } else { createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id2, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators); var service_leg_record = record.load({ id: service_leg_id, type: 'customrecord_service_leg' }) service_leg_record.setValue({ fieldId: 'custrecord_app_ser_leg_daily_job_create', value: 1}); service_leg_record.save(); } } log.audit({ title: 'Finised Run Plan' }); } } } catch (e) { // statements var body = 'Error on one of the following: \n'; body += 'Service Leg ID: ' + service_leg_id + '\n'; body += 'Service Leg Freq ID: ' + service_freq_id + '\n'; body += 'Run Plan: ' + service_freq_run_plan_id + '\n'; body += 'e: ' + e + '\n'; email.send({ author: 112209, recipients: '[email protected]', subject: 'Create App Jobs', body: body}) log.debug({ title: 'ERROR', details: body }); } old_service_id = service_id; count++; return true; }); log.audit({ title: 'Total Count for ' + zee_name, details: count }); if (exit == false) { var zee_record = record.load({type: 'partner', id: zee_id}); zee_record.setValue({ fieldId: 'custentity_zee_app_job_created', value: 1}); // REMEMBER TO UNCOMMENT zee_record.save(); reschedule = task.create({ taskType: task.TaskType.SCHEDULED_SCRIPT, scriptId: 'customscript_ss_create_app_jobs_2', deploymentId: 'customdeploy_ss_create_app_jobs_2' }); log.emergency({​​​​​ title: 'Reschedule Return - END LOOP' }); var rescheduled = reschedule.submit(); // if (task.checkStatus({​​​​​ taskId: rescheduled}​​​​​) == false) {​​​​​ // // exit = true; // log.debug({ // title: 'Reschedule Status False' // }); // return false; // }​​​​​ } // To remove or not too remove?!?!? // return true; }); } function createAppJobGroup(service_leg_service_text, service_leg_customer, service_leg_zee, service_id) { var app_job_group_rec = record.create({ type: 'customrecord_jobgroup' }); log.audit({ title: 'Create Jobs Group Activated', details: app_job_group_rec }); app_job_group_rec.setValue({ fieldId: 'name', value: service_leg_service_text + '_' + date_of_week}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_ref', value: service_leg_service_text + '_' + date_of_week}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_customer', value: service_leg_customer}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_franchisee', value: service_leg_zee}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_service', value: service_id}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_status', value: 4}); var app_job_group_id = app_job_group_rec.save(); return app_job_group_id; } function createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators) { var app_job_rec = record.create({ type: 'customrecord_job' }); log.audit({ title: 'Create Jobs Function Activated', details: app_job_rec }); app_job_rec.setValue({ fieldId: 'custrecord_job_franchisee', value: service_leg_zee}); log.audit({ title: 'Adhoc Value', details: service_freq_adhoc }); // if (service_freq_adhoc == 'T') { if (service_freq_adhoc == true) { if (service_leg_location_type == 2) { app_job_rec.setValue({ fieldId:'custrecord_app_job_stop_name', value: 'ADHOC - ' + service_leg_name + ' - ' + service_leg_customer_text}); } else { app_job_rec.setValue({ fieldId:'custrecord_app_job_stop_name', value: 'ADHOC - ' + service_leg_name}); } } else { app_job_rec.setValue({ fieldId: 'custrecord_app_job_stop_name', value: service_leg_name}); } app_job_rec.setValue({ fieldId: 'custrecord_job_customer', value: service_leg_customer}); app_job_rec.setValue({ fieldId: 'custrecord_job_source', value: 6}); app_job_rec.setValue({ fieldId: 'custrecord_job_service', value: service_id}); app_job_rec.setValue({ fieldId: 'custrecord_job_service_price', value: service_price}); app_job_rec.setValue({ fieldId: 'custrecord_job_stop', value: service_leg_id}); app_job_rec.setValue({ fieldId: 'custrecord159', value: service_leg_id}); app_job_rec.setValue({ fieldId: 'custrecord_job_status', value: 1}); var new_date_of_week = format.parse({ type: format.Type.DATE, value: date_of_week }); app_job_rec.setValue({ fieldId: 'custrecord_job_date_scheduled', value: new_date_of_week}); var convert_curr_arr = convertTo24Hour(service_freq_time_current); var curr_arr = convert_curr_arr.split(':'); var curr_1 = parseInt(curr_arr[0]); var curr_2 = parseInt(curr_arr[1]); var currTimeVar = new Date (); currTimeVar.setHours(curr_1, curr_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled', value: currTimeVar}); var convert_end_arr = convertTo24Hour(service_freq_time_end); var end_arr = convert_end_arr.split(':'); var end_1 = parseInt(end_arr[0]); var end_2 = parseInt(end_arr[1]); var endTimeVar = new Date (); endTimeVar.setHours(end_1, end_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled_after', value: endTimeVar}); var convert_start_arr = convertTo24Hour(service_freq_time_start); var start_arr = convert_start_arr.split(':'); var start_1 = parseInt(start_arr[0]); var start_2 = parseInt(start_arr[1]); var startTimeVar = new Date ();; startTimeVar.setHours(start_1, start_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled_before', value: startTimeVar}); app_job_rec.setValue({ fieldId: 'custrecord_job_service_leg', value: service_leg_no}); app_job_rec.setValue({ fieldId: 'custrecord_job_group', value: app_job_group_id}); // app_job_rec.setValue({ fieldId: 'custrecord_job_group_status'}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_st_name_no', value: service_leg_addr_st_num}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_suburb', value: service_leg_addr_suburb}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_state', value: service_leg_addr_state}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_post_code', value: service_leg_addr_postcode}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_lat', value: service_leg_addr_lat}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_lon', value: service_leg_addr_lon}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_notes', value: service_leg_notes}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_run', value: service_freq_run_plan_id}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_location_type', value: service_leg_location_type}); app_job_rec.setValue({ fieldId: 'custrecord_job_multiple_operators', value: service_multiple_operators}); // log.audit({ // title: 'Create App Jobs Completed', // }) var create_app_id = app_job_rec.save(); log.audit({ title: 'Create_App Saved with ID', details: create_app_id }); } function convertTo24Hour(time) { // nlapiLogExecution('DEBUG', 'time', time); var hours = parseInt(time.substr(0, 2)); if (time.indexOf('AM') != -1 && hours == 12) { time = time.replace('12', '0'); } if (time.indexOf('AM') != -1 && hours < 10) { time = time.replace(hours, ('0' + hours)); } if (time.indexOf('PM') != -1 && hours < 12) { time = time.replace(hours, (hours + 12)); } return time.replace(/( AM| PM)/, ''); } function onTimeChange(value) { if (!isNullorEmpty(value)) { var timeSplit = value.split(':'), hours, minutes, meridian; hours = timeSplit[0]; minutes = timeSplit[1]; if (hours > 12) { meridian = 'PM'; hours -= 12; } else if (hours < 12) { meridian = 'AM'; if (hours == 0) { hours = 12; } } else { meridian = 'PM'; } return (hours + ':' + minutes + ' ' + meridian); } } function isNullorEmpty(val) { if (val == '' || val == null) { return true; } else { return false; } } return { execute: main } });
638
[{"tag": "EMAIL", "value": "[email protected]", "start": 26518, "end": 26550}]
true
1
/** * @NApiVersion 2.x * @NScriptType ScheduledScript * @NAmdConfig ./custom_modules_config.json * * Module Description * * @Author: ankith.ravindran * @Date: 2018-09-19 13:20:56 * @Last Modified by: Anesu Chakaingesu * @Last Modified time: 2020-04-30 14:56:03 */ define(['N/ui/serverWidget', 'N/email', 'N/runtime', 'N/search', 'N/record', 'N/http', 'N/log', 'N/redirect', 'N/task', 'moment2', 'N/format'], function(ui, email, runtime, search, record, http, log, redirect, task, moment, format) { // log.debug({ // title: 'moment Defined', // details: JSON.stringify(moment) // }); var days_of_week = []; days_of_week[0] = 0; days_of_week[1] = 'custrecord_service_freq_stop.custrecord_service_freq_day_mon'; days_of_week[2] = 'custrecord_service_freq_stop.custrecord_service_freq_day_tue'; days_of_week[3] = 'custrecord_service_freq_stop.custrecord_service_freq_day_wed'; days_of_week[4] = 'custrecord_service_freq_stop.custrecord_service_freq_day_thu'; days_of_week[5] = 'custrecord_service_freq_stop.custrecord_service_freq_day_fri'; days_of_week[6] = 6; var days_of_week2 = []; days_of_week2[0] = 0; days_of_week2[1] = 'custrecord_service_freq_day_mon'; days_of_week2[2] = 'custrecord_service_freq_day_tue'; days_of_week2[3] = 'custrecord_service_freq_day_wed'; days_of_week2[4] = 'custrecord_service_freq_day_thu'; days_of_week2[5] = 'custrecord_service_freq_day_fri'; days_of_week2[6] = 6; var usage_threshold = 200; //20 var usage_threshold_invoice = 1000; //1000 var adhoc_inv_deploy = 'customdeploy2'; var prev_inv_deploy = null; var ctx = runtime.getCurrentScript(); var date_of_week; function main(){ var day = moment().utc().day(); var date = moment().utc().add(1, 'days').date(); var month = moment().utc().month(); var year = moment().utc().year(); var startDate = moment([year, month]); var endDate = moment(startDate).endOf('month').date(); if(moment().utc().date() == endDate){ date_of_week = date + '/' + (month + 2) + '/' + year; } else { date_of_week = date + '/' + (month + 1) + '/' + year; } // date_of_week = date + '/' + (month + 1) + '/' + year; log.audit({ title: 'moment().utc()', details: moment().utc() }) log.audit({ title: 'day', details: day }) log.audit({ title: 'original date', details: moment().utc().date() }) log.audit({ title: 'date', details: date }) log.audit({ title: 'Last Day of Month', details: endDate }) log.audit({ title: 'month', details: month }) log.audit({ title: 'year', details: year }) log.audit({ title: 'date_of_week', details: date_of_week }) log.audit({ title: 'days_of_week[day + 1]', details: days_of_week[day + 1] }); log.audit({ title: 'days_of_week[day]', details: days_of_week[day] }); log.audit({ title: 'prev_deployment', details: ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }) }) if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }))) { prev_inv_deploy = ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }) } else { prev_inv_deploy = ctx.deploymentId; } var zeeSearch = search.load({ type: 'partner', id: 'customsearch_rp_zee_no_job_created_2_2' }); var resultZee = zeeSearch.run(); //.getRange({ start: 0, end: 1}) // log.audit({ // title: 'searchResultZee', // details: resultZee // }) resultZee.each(function(searchResultZee) { var zee_id = searchResultZee.getValue({ name: "internalid"}); // var zee_id = 215 // Alexandria // var zee_id = 5386 // Arncliffe // var zee_id = 621451 // Gold Coast // var zee_id = 780481 // TEST - ACT // var zee_id = 779884 // TEST - NSW // var zee_id = 626844 // TEST - QLD // var zee_id = 626428 // TEST - VIC // var zee_id = 626845 // TEST - WA var zee_name = searchResultZee.getValue({ name: "entityid"}); log.debug({ title: 'Zee Name', details: zee_name }); //SEARCH: RP - Service Leg Frequency - All - Create App Jobs // if (day != 0 && day != 6){ var runPlanSearch; new_day = day + 1; log.debug({ title: 'day', details: 'New Day' + new_day + 'Old Day' + day }); switch (new_day){ case 1: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_mon'}); break; case 2: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_tue'}); break; case 3: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_wed'}); break; case 4: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_thu'}); break; case 5: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_fri'}); break; } log.debug({ title: 'runPlanSearch', details: runPlanSearch }) // } // var runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_jo_2'}); // customsearch_rp_leg_freq_create_app_jo_2 or customsearch_rp_leg_freq_create_app_jobs // log.debug({ // title: 'days_of_week[day]', // details: days_of_week[day] // }); // log.debug({ // title: 'service_leg_customer', // details: service_leg_customer // }); if (day != 0 && day != 6) { var filterExpression = []; var filterExpression = runPlanSearch.filterExpression; filterExpression.push('AND'); filterExpression.push([ [days_of_week[day + 1], search.Operator.IS , 'T'], // customer id "OR", ["custrecord_service_freq_stop.custrecord_service_freq_day_adhoc", search.Operator.IS , 'T'] ]); filterExpression.push("AND", ["isinactive", search.Operator.IS , "F"]); filterExpression.push("AND", ["custrecord_service_leg_customer.partner", search.Operator.IS , zee_id]); filterExpression.push("AND", ["custrecord_service_leg_customer.status", search.Operator.ANYOF, "32", "13"]); filterExpression.push("AND", ["custrecord_service_leg_service.isinactive", search.Operator.IS , "F"]); filterExpression.push("AND", ["custrecord_service_freq_stop.internalid", search.Operator.NONEOF, "@NONE@"]); filterExpression.push("AND", [ ["formulatext: CASE WHEN TO_CHAR({custrecord_service_leg_closing_date}, 'DD/MM/YYYY') <= TO_CHAR(SYSDATE, 'DD/MM/YYYY') THEN 'T' ELSE 'F' END", search.Operator.IS , "F"], "AND", ["formulatext: CASE WHEN TO_CHAR({custrecord_service_leg_opening_date}, 'DD/MM/YYYY') > TO_CHAR(SYSDATE, 'DD/MM/YYYY') THEN 'T' ELSE 'F' END", search.Operator.IS, "F"] ]); filterExpression.push("AND", ["custrecord_app_ser_leg_daily_job_create", search.Operator.ANYOF, "2", "@NONE@"]); // runPlanSearch.filterExpression = filterExpression; } log.debug({ title: 'filterExpression', details: runPlanSearch.filterExpression }); var resultRunPlan = runPlanSearch.run(); // var runPlanResult = resultRunPlan.getResults() // log.debug({ // title: 'Length', // details: runPlanResult.length // }) if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_old_service_id_create_app'}))) { var old_service_id = ctx.getParameter({ name: 'custscript_rp_old_service_id_create_app'}); } else { var old_service_id; } if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_app_job_group_id_create_app'}))) { var app_job_group_id2 = ctx.getParameter({ name: 'custscript_rp_app_job_group_id_create_app'}); } else { var app_job_group_id2; } var count = 0; var exit = false; resultRunPlan.each(function(searchResult) { var service_leg_id = searchResult.getValue({ name: "internalid", join: null, summary: search.Summary.GROUP}); var service_leg_name = searchResult.getValue({ name: "name", join: null, summary: search.Summary.GROUP}); var service_leg_zee = searchResult.getValue({ name: "custrecord_service_leg_franchisee", join: null, summary: search.Summary.GROUP}); var service_leg_customer = searchResult.getValue({ name: "custrecord_service_leg_customer", join: null, summary: search.Summary.GROUP}); var service_leg_customer_text = searchResult.getText({ name: "custrecord_service_leg_customer", join: null, summary: search.Summary.GROUP}); var service_id = searchResult.getValue({ name: "internalid", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_leg_service = searchResult.getValue({ name: "custrecord_service_leg_service", join: null, summary: search.Summary.GROUP}); var service_leg_service_text = searchResult.getText({ name: "custrecord_service_leg_service", join: null, summary: search.Summary.GROUP}); var service_price = searchResult.getValue({ name: "custrecord_service_price", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_cat = searchResult.getValue({ name: "custrecord_service_category", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_leg_no = searchResult.getValue({ name: "custrecord_service_leg_number", join: null, summary: search.Summary.GROUP}); var service_leg_ncl = searchResult.getValue({ name: "custrecord_service_leg_non_cust_location", join: null, summary: search.Summary.GROUP}); var service_leg_addr = searchResult.getValue({ name: "custrecord_service_leg_addr", join: null, summary: search.Summary.GROUP}); var service_leg_addr_postal = searchResult.getValue({ name: "custrecord_service_leg_addr_postal", join: null, summary: search.Summary.GROUP}); var service_leg_addr_subdwelling = searchResult.getValue({ name: "custrecord_service_leg_addr_subdwelling", join: null, summary: search.Summary.GROUP}); var service_leg_addr_st_num = searchResult.getValue({ name: "custrecord_service_leg_addr_st_num_name", join: null, summary: search.Summary.GROUP}); var service_leg_addr_suburb = searchResult.getValue({ name: "custrecord_service_leg_addr_suburb", join: null, summary: search.Summary.GROUP}); var service_leg_addr_state = searchResult.getValue({ name: "custrecord_service_leg_addr_state", join: null, summary: search.Summary.GROUP}); var service_leg_addr_postcode = searchResult.getValue({ name: "custrecord_service_leg_addr_postcode", join: null, summary: search.Summary.GROUP}); var service_leg_addr_lat = searchResult.getValue({ name: "custrecord_service_leg_addr_lat", join: null, summary: search.Summary.GROUP}); var service_leg_addr_lon = searchResult.getValue({ name: "custrecord_service_leg_addr_lon", join: null, summary: search.Summary.GROUP}); var service_leg_type = searchResult.getValue({ name: "custrecord_service_leg_type", join: null, summary: search.Summary.GROUP}); var service_leg_duration = searchResult.getValue({ name: "custrecord_service_leg_duration", join: null, summary: search.Summary.GROUP}); var service_leg_notes = searchResult.getValue({ name: "custrecord_service_leg_notes", join: null, summary: search.Summary.GROUP}); var service_leg_location_type = searchResult.getValue({ name: "custrecord_service_leg_location_type", join: null, summary: search.Summary.GROUP}); var service_leg_transfer_type = searchResult.getValue({ name: "custrecord_service_leg_trf_type", join: null, summary: search.Summary.GROUP}); var service_leg_transfer_linked_stop = searchResult.getValue({ name: "custrecord_service_leg_trf_linked_stop", join: null, summary: search.Summary.GROUP}); var service_freq_id = searchResult.getValue({ name: "internalid", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_mon = searchResult.getValue({ name: "custrecord_service_freq_day_mon", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_tue = searchResult.getValue({ name: "custrecord_service_freq_day_tue", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_wed = searchResult.getValue({ name: "custrecord_service_freq_day_wed", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_thu = searchResult.getValue({ name: "custrecord_service_freq_day_thu", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_fri = searchResult.getValue({ name: "custrecord_service_freq_day_fri", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_adhoc = searchResult.getValue({ name: "custrecord_service_freq_day_adhoc", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_current = searchResult.getValue({ name: "custrecord_service_freq_time_current", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_start = searchResult.getValue({ name: "custrecord_service_freq_time_start", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_end = searchResult.getValue({ name: "custrecord_service_freq_time_end", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_run_plan_id = searchResult.getValue({ name: "custrecord_service_freq_run_plan", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_operator = searchResult.getValue({ name: "custrecord_service_freq_operator", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_zee = searchResult.getValue({ name: "custrecord_service_freq_franchisee", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_multiple_operators = searchResult.getValue({ name: "custrecord_multiple_operators", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var street_no_name = null; log.debug({ title: 'service_leg_id', details: service_leg_id }); try { // statements if (!isNullorEmpty(service_freq_run_plan_id)) { log.debug({ title: 'service_freq_run_plan_id', details: service_freq_run_plan_id }) var run_plan_record = record.load({ id: service_freq_run_plan_id, type: 'customrecord_run_plan' }) var run_plan_inactive = run_plan_record.getValue({ fieldId: 'isinactive'}); log.debug({ title: 'run_plan_inactive ?', details: run_plan_inactive }) var serviceLegRecord = record.load({ type: 'customrecord_service_freq', id: service_freq_id }); var weekOfDay = serviceLegRecord.getValue({ fieldId: days_of_week2[day + 1]}); log.debug({ title: 'weekOfDay', details: weekOfDay }) if (weekOfDay == false && service_freq_adhoc == false) { } else { if (run_plan_inactive == false) { log.audit({ title: 'Run Plan Inactive = False' }); if (isNullorEmpty(service_leg_addr_subdwelling) && !isNullorEmpty(service_leg_addr_st_num)) { street_no_name = service_leg_addr_st_num; } else if (!isNullorEmpty(service_leg_addr_subdwelling) && isNullorEmpty(service_leg_addr_st_num)) { street_no_name = service_leg_addr_subdwelling; } else { street_no_name = service_leg_addr_subdwelling + ', ' + service_leg_addr_st_num; } service_leg_addr_st_num = street_no_name; if (old_service_id != service_id) { var usage_loopstart_cust = ctx.getRemainingUsage(); log.debug({ title: 'usage_loopstart_cust', details: usage_loopstart_cust }) log.debug({ title: 'usage_threshold', details: usage_threshold }) if (usage_loopstart_cust < usage_threshold) { var params = { custscript_rp_prev_deployment_create_app: ctx.deploymentId, custscript_rp_old_service_id_create_app: old_service_id, custscript_rp_app_job_group_id_create_app: app_job_group_id2 } reschedule = task.create({ taskType: task.TaskType.SCHEDULED_SCRIPT, scriptId: 'customscript_ss_create_app_jobs_2', deploymentId: 'customdeploy_ss_create_app_jobs_2', params: params }); log.audit({​​​​​ title: 'Reschedule Return - IN LOOP' }); var rescheduled = reschedule.submit(); // if (task.checkStatus({​​​​​ taskId: reschedule}​​​​​) == false) {​​​​​ // exit = true; // return false; // }​​​​​ } createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id2, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators); var service_leg_record = record.load({ id: service_leg_id, type: 'customrecord_service_leg' }) service_leg_record.setValue({ fieldId: 'custrecord_app_ser_leg_daily_job_create', value: 1}); var service = service_leg_record.save(); log.audit({ title: 'Service Leg - Saved', details: service }) app_job_group_id2 = createAppJobGroup(service_leg_service_text, service_leg_customer, service_leg_zee, service_id); } else { createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id2, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators); var service_leg_record = record.load({ id: service_leg_id, type: 'customrecord_service_leg' }) service_leg_record.setValue({ fieldId: 'custrecord_app_ser_leg_daily_job_create', value: 1}); service_leg_record.save(); } } log.audit({ title: 'Finised Run Plan' }); } } } catch (e) { // statements var body = 'Error on one of the following: \n'; body += 'Service Leg ID: ' + service_leg_id + '\n'; body += 'Service Leg Freq ID: ' + service_freq_id + '\n'; body += 'Run Plan: ' + service_freq_run_plan_id + '\n'; body += 'e: ' + e + '\n'; email.send({ author: 112209, recipients: '[email protected]', subject: 'Create App Jobs', body: body}) log.debug({ title: 'ERROR', details: body }); } old_service_id = service_id; count++; return true; }); log.audit({ title: 'Total Count for ' + zee_name, details: count }); if (exit == false) { var zee_record = record.load({type: 'partner', id: zee_id}); zee_record.setValue({ fieldId: 'custentity_zee_app_job_created', value: 1}); // REMEMBER TO UNCOMMENT zee_record.save(); reschedule = task.create({ taskType: task.TaskType.SCHEDULED_SCRIPT, scriptId: 'customscript_ss_create_app_jobs_2', deploymentId: 'customdeploy_ss_create_app_jobs_2' }); log.emergency({​​​​​ title: 'Reschedule Return - END LOOP' }); var rescheduled = reschedule.submit(); // if (task.checkStatus({​​​​​ taskId: rescheduled}​​​​​) == false) {​​​​​ // // exit = true; // log.debug({ // title: 'Reschedule Status False' // }); // return false; // }​​​​​ } // To remove or not too remove?!?!? // return true; }); } function createAppJobGroup(service_leg_service_text, service_leg_customer, service_leg_zee, service_id) { var app_job_group_rec = record.create({ type: 'customrecord_jobgroup' }); log.audit({ title: 'Create Jobs Group Activated', details: app_job_group_rec }); app_job_group_rec.setValue({ fieldId: 'name', value: service_leg_service_text + '_' + date_of_week}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_ref', value: service_leg_service_text + '_' + date_of_week}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_customer', value: service_leg_customer}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_franchisee', value: service_leg_zee}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_service', value: service_id}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_status', value: 4}); var app_job_group_id = app_job_group_rec.save(); return app_job_group_id; } function createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators) { var app_job_rec = record.create({ type: 'customrecord_job' }); log.audit({ title: 'Create Jobs Function Activated', details: app_job_rec }); app_job_rec.setValue({ fieldId: 'custrecord_job_franchisee', value: service_leg_zee}); log.audit({ title: 'Adhoc Value', details: service_freq_adhoc }); // if (service_freq_adhoc == 'T') { if (service_freq_adhoc == true) { if (service_leg_location_type == 2) { app_job_rec.setValue({ fieldId:'custrecord_app_job_stop_name', value: 'ADHOC - ' + service_leg_name + ' - ' + service_leg_customer_text}); } else { app_job_rec.setValue({ fieldId:'custrecord_app_job_stop_name', value: 'ADHOC - ' + service_leg_name}); } } else { app_job_rec.setValue({ fieldId: 'custrecord_app_job_stop_name', value: service_leg_name}); } app_job_rec.setValue({ fieldId: 'custrecord_job_customer', value: service_leg_customer}); app_job_rec.setValue({ fieldId: 'custrecord_job_source', value: 6}); app_job_rec.setValue({ fieldId: 'custrecord_job_service', value: service_id}); app_job_rec.setValue({ fieldId: 'custrecord_job_service_price', value: service_price}); app_job_rec.setValue({ fieldId: 'custrecord_job_stop', value: service_leg_id}); app_job_rec.setValue({ fieldId: 'custrecord159', value: service_leg_id}); app_job_rec.setValue({ fieldId: 'custrecord_job_status', value: 1}); var new_date_of_week = format.parse({ type: format.Type.DATE, value: date_of_week }); app_job_rec.setValue({ fieldId: 'custrecord_job_date_scheduled', value: new_date_of_week}); var convert_curr_arr = convertTo24Hour(service_freq_time_current); var curr_arr = convert_curr_arr.split(':'); var curr_1 = parseInt(curr_arr[0]); var curr_2 = parseInt(curr_arr[1]); var currTimeVar = new Date (); currTimeVar.setHours(curr_1, curr_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled', value: currTimeVar}); var convert_end_arr = convertTo24Hour(service_freq_time_end); var end_arr = convert_end_arr.split(':'); var end_1 = parseInt(end_arr[0]); var end_2 = parseInt(end_arr[1]); var endTimeVar = new Date (); endTimeVar.setHours(end_1, end_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled_after', value: endTimeVar}); var convert_start_arr = convertTo24Hour(service_freq_time_start); var start_arr = convert_start_arr.split(':'); var start_1 = parseInt(start_arr[0]); var start_2 = parseInt(start_arr[1]); var startTimeVar = new Date ();; startTimeVar.setHours(start_1, start_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled_before', value: startTimeVar}); app_job_rec.setValue({ fieldId: 'custrecord_job_service_leg', value: service_leg_no}); app_job_rec.setValue({ fieldId: 'custrecord_job_group', value: app_job_group_id}); // app_job_rec.setValue({ fieldId: 'custrecord_job_group_status'}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_st_name_no', value: service_leg_addr_st_num}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_suburb', value: service_leg_addr_suburb}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_state', value: service_leg_addr_state}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_post_code', value: service_leg_addr_postcode}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_lat', value: service_leg_addr_lat}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_lon', value: service_leg_addr_lon}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_notes', value: service_leg_notes}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_run', value: service_freq_run_plan_id}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_location_type', value: service_leg_location_type}); app_job_rec.setValue({ fieldId: 'custrecord_job_multiple_operators', value: service_multiple_operators}); // log.audit({ // title: 'Create App Jobs Completed', // }) var create_app_id = app_job_rec.save(); log.audit({ title: 'Create_App Saved with ID', details: create_app_id }); } function convertTo24Hour(time) { // nlapiLogExecution('DEBUG', 'time', time); var hours = parseInt(time.substr(0, 2)); if (time.indexOf('AM') != -1 && hours == 12) { time = time.replace('12', '0'); } if (time.indexOf('AM') != -1 && hours < 10) { time = time.replace(hours, ('0' + hours)); } if (time.indexOf('PM') != -1 && hours < 12) { time = time.replace(hours, (hours + 12)); } return time.replace(/( AM| PM)/, ''); } function onTimeChange(value) { if (!isNullorEmpty(value)) { var timeSplit = value.split(':'), hours, minutes, meridian; hours = timeSplit[0]; minutes = timeSplit[1]; if (hours > 12) { meridian = 'PM'; hours -= 12; } else if (hours < 12) { meridian = 'AM'; if (hours == 0) { hours = 12; } } else { meridian = 'PM'; } return (hours + ':' + minutes + ' ' + meridian); } } function isNullorEmpty(val) { if (val == '' || val == null) { return true; } else { return false; } } return { execute: main } });
true
/** * @NApiVersion 2.x * @NScriptType ScheduledScript * @NAmdConfig ./custom_modules_config.json * * Module Description * * @Author: ankith.ravindran * @Date: 2018-09-19 13:20:56 * @Last Modified by: Anesu Chakaingesu * @Last Modified time: 2020-04-30 14:56:03 */ define(['N/ui/serverWidget', 'N/email', 'N/runtime', 'N/search', 'N/record', 'N/http', 'N/log', 'N/redirect', 'N/task', 'moment2', 'N/format'], function(ui, email, runtime, search, record, http, log, redirect, task, moment, format) { // log.debug({ // title: 'moment Defined', // details: JSON.stringify(moment) // }); var days_of_week = []; days_of_week[0] = 0; days_of_week[1] = 'custrecord_service_freq_stop.custrecord_service_freq_day_mon'; days_of_week[2] = 'custrecord_service_freq_stop.custrecord_service_freq_day_tue'; days_of_week[3] = 'custrecord_service_freq_stop.custrecord_service_freq_day_wed'; days_of_week[4] = 'custrecord_service_freq_stop.custrecord_service_freq_day_thu'; days_of_week[5] = 'custrecord_service_freq_stop.custrecord_service_freq_day_fri'; days_of_week[6] = 6; var days_of_week2 = []; days_of_week2[0] = 0; days_of_week2[1] = 'custrecord_service_freq_day_mon'; days_of_week2[2] = 'custrecord_service_freq_day_tue'; days_of_week2[3] = 'custrecord_service_freq_day_wed'; days_of_week2[4] = 'custrecord_service_freq_day_thu'; days_of_week2[5] = 'custrecord_service_freq_day_fri'; days_of_week2[6] = 6; var usage_threshold = 200; //20 var usage_threshold_invoice = 1000; //1000 var adhoc_inv_deploy = 'customdeploy2'; var prev_inv_deploy = null; var ctx = runtime.getCurrentScript(); var date_of_week; function main(){ var day = moment().utc().day(); var date = moment().utc().add(1, 'days').date(); var month = moment().utc().month(); var year = moment().utc().year(); var startDate = moment([year, month]); var endDate = moment(startDate).endOf('month').date(); if(moment().utc().date() == endDate){ date_of_week = date + '/' + (month + 2) + '/' + year; } else { date_of_week = date + '/' + (month + 1) + '/' + year; } // date_of_week = date + '/' + (month + 1) + '/' + year; log.audit({ title: 'moment().utc()', details: moment().utc() }) log.audit({ title: 'day', details: day }) log.audit({ title: 'original date', details: moment().utc().date() }) log.audit({ title: 'date', details: date }) log.audit({ title: 'Last Day of Month', details: endDate }) log.audit({ title: 'month', details: month }) log.audit({ title: 'year', details: year }) log.audit({ title: 'date_of_week', details: date_of_week }) log.audit({ title: 'days_of_week[day + 1]', details: days_of_week[day + 1] }); log.audit({ title: 'days_of_week[day]', details: days_of_week[day] }); log.audit({ title: 'prev_deployment', details: ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }) }) if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }))) { prev_inv_deploy = ctx.getParameter({ name: 'custscript_rp_prev_deployment_create_app' }) } else { prev_inv_deploy = ctx.deploymentId; } var zeeSearch = search.load({ type: 'partner', id: 'customsearch_rp_zee_no_job_created_2_2' }); var resultZee = zeeSearch.run(); //.getRange({ start: 0, end: 1}) // log.audit({ // title: 'searchResultZee', // details: resultZee // }) resultZee.each(function(searchResultZee) { var zee_id = searchResultZee.getValue({ name: "internalid"}); // var zee_id = 215 // Alexandria // var zee_id = 5386 // Arncliffe // var zee_id = 621451 // Gold Coast // var zee_id = 780481 // TEST - ACT // var zee_id = 779884 // TEST - NSW // var zee_id = 626844 // TEST - QLD // var zee_id = 626428 // TEST - VIC // var zee_id = 626845 // TEST - WA var zee_name = searchResultZee.getValue({ name: "entityid"}); log.debug({ title: 'Zee Name', details: zee_name }); //SEARCH: RP - Service Leg Frequency - All - Create App Jobs // if (day != 0 && day != 6){ var runPlanSearch; new_day = day + 1; log.debug({ title: 'day', details: 'New Day' + new_day + 'Old Day' + day }); switch (new_day){ case 1: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_mon'}); break; case 2: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_tue'}); break; case 3: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_wed'}); break; case 4: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_thu'}); break; case 5: runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_fri'}); break; } log.debug({ title: 'runPlanSearch', details: runPlanSearch }) // } // var runPlanSearch = search.load({ type: 'customrecord_service_leg', id: 'customsearch_rp_leg_freq_create_app_jo_2'}); // customsearch_rp_leg_freq_create_app_jo_2 or customsearch_rp_leg_freq_create_app_jobs // log.debug({ // title: 'days_of_week[day]', // details: days_of_week[day] // }); // log.debug({ // title: 'service_leg_customer', // details: service_leg_customer // }); if (day != 0 && day != 6) { var filterExpression = []; var filterExpression = runPlanSearch.filterExpression; filterExpression.push('AND'); filterExpression.push([ [days_of_week[day + 1], search.Operator.IS , 'T'], // customer id "OR", ["custrecord_service_freq_stop.custrecord_service_freq_day_adhoc", search.Operator.IS , 'T'] ]); filterExpression.push("AND", ["isinactive", search.Operator.IS , "F"]); filterExpression.push("AND", ["custrecord_service_leg_customer.partner", search.Operator.IS , zee_id]); filterExpression.push("AND", ["custrecord_service_leg_customer.status", search.Operator.ANYOF, "32", "13"]); filterExpression.push("AND", ["custrecord_service_leg_service.isinactive", search.Operator.IS , "F"]); filterExpression.push("AND", ["custrecord_service_freq_stop.internalid", search.Operator.NONEOF, "@NONE@"]); filterExpression.push("AND", [ ["formulatext: CASE WHEN TO_CHAR({custrecord_service_leg_closing_date}, 'DD/MM/YYYY') <= TO_CHAR(SYSDATE, 'DD/MM/YYYY') THEN 'T' ELSE 'F' END", search.Operator.IS , "F"], "AND", ["formulatext: CASE WHEN TO_CHAR({custrecord_service_leg_opening_date}, 'DD/MM/YYYY') > TO_CHAR(SYSDATE, 'DD/MM/YYYY') THEN 'T' ELSE 'F' END", search.Operator.IS, "F"] ]); filterExpression.push("AND", ["custrecord_app_ser_leg_daily_job_create", search.Operator.ANYOF, "2", "@NONE@"]); // runPlanSearch.filterExpression = filterExpression; } log.debug({ title: 'filterExpression', details: runPlanSearch.filterExpression }); var resultRunPlan = runPlanSearch.run(); // var runPlanResult = resultRunPlan.getResults() // log.debug({ // title: 'Length', // details: runPlanResult.length // }) if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_old_service_id_create_app'}))) { var old_service_id = ctx.getParameter({ name: 'custscript_rp_old_service_id_create_app'}); } else { var old_service_id; } if (!isNullorEmpty(ctx.getParameter({ name: 'custscript_rp_app_job_group_id_create_app'}))) { var app_job_group_id2 = ctx.getParameter({ name: 'custscript_rp_app_job_group_id_create_app'}); } else { var app_job_group_id2; } var count = 0; var exit = false; resultRunPlan.each(function(searchResult) { var service_leg_id = searchResult.getValue({ name: "internalid", join: null, summary: search.Summary.GROUP}); var service_leg_name = searchResult.getValue({ name: "name", join: null, summary: search.Summary.GROUP}); var service_leg_zee = searchResult.getValue({ name: "custrecord_service_leg_franchisee", join: null, summary: search.Summary.GROUP}); var service_leg_customer = searchResult.getValue({ name: "custrecord_service_leg_customer", join: null, summary: search.Summary.GROUP}); var service_leg_customer_text = searchResult.getText({ name: "custrecord_service_leg_customer", join: null, summary: search.Summary.GROUP}); var service_id = searchResult.getValue({ name: "internalid", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_leg_service = searchResult.getValue({ name: "custrecord_service_leg_service", join: null, summary: search.Summary.GROUP}); var service_leg_service_text = searchResult.getText({ name: "custrecord_service_leg_service", join: null, summary: search.Summary.GROUP}); var service_price = searchResult.getValue({ name: "custrecord_service_price", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_cat = searchResult.getValue({ name: "custrecord_service_category", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var service_leg_no = searchResult.getValue({ name: "custrecord_service_leg_number", join: null, summary: search.Summary.GROUP}); var service_leg_ncl = searchResult.getValue({ name: "custrecord_service_leg_non_cust_location", join: null, summary: search.Summary.GROUP}); var service_leg_addr = searchResult.getValue({ name: "custrecord_service_leg_addr", join: null, summary: search.Summary.GROUP}); var service_leg_addr_postal = searchResult.getValue({ name: "custrecord_service_leg_addr_postal", join: null, summary: search.Summary.GROUP}); var service_leg_addr_subdwelling = searchResult.getValue({ name: "custrecord_service_leg_addr_subdwelling", join: null, summary: search.Summary.GROUP}); var service_leg_addr_st_num = searchResult.getValue({ name: "custrecord_service_leg_addr_st_num_name", join: null, summary: search.Summary.GROUP}); var service_leg_addr_suburb = searchResult.getValue({ name: "custrecord_service_leg_addr_suburb", join: null, summary: search.Summary.GROUP}); var service_leg_addr_state = searchResult.getValue({ name: "custrecord_service_leg_addr_state", join: null, summary: search.Summary.GROUP}); var service_leg_addr_postcode = searchResult.getValue({ name: "custrecord_service_leg_addr_postcode", join: null, summary: search.Summary.GROUP}); var service_leg_addr_lat = searchResult.getValue({ name: "custrecord_service_leg_addr_lat", join: null, summary: search.Summary.GROUP}); var service_leg_addr_lon = searchResult.getValue({ name: "custrecord_service_leg_addr_lon", join: null, summary: search.Summary.GROUP}); var service_leg_type = searchResult.getValue({ name: "custrecord_service_leg_type", join: null, summary: search.Summary.GROUP}); var service_leg_duration = searchResult.getValue({ name: "custrecord_service_leg_duration", join: null, summary: search.Summary.GROUP}); var service_leg_notes = searchResult.getValue({ name: "custrecord_service_leg_notes", join: null, summary: search.Summary.GROUP}); var service_leg_location_type = searchResult.getValue({ name: "custrecord_service_leg_location_type", join: null, summary: search.Summary.GROUP}); var service_leg_transfer_type = searchResult.getValue({ name: "custrecord_service_leg_trf_type", join: null, summary: search.Summary.GROUP}); var service_leg_transfer_linked_stop = searchResult.getValue({ name: "custrecord_service_leg_trf_linked_stop", join: null, summary: search.Summary.GROUP}); var service_freq_id = searchResult.getValue({ name: "internalid", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_mon = searchResult.getValue({ name: "custrecord_service_freq_day_mon", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_tue = searchResult.getValue({ name: "custrecord_service_freq_day_tue", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_wed = searchResult.getValue({ name: "custrecord_service_freq_day_wed", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_thu = searchResult.getValue({ name: "custrecord_service_freq_day_thu", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_fri = searchResult.getValue({ name: "custrecord_service_freq_day_fri", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_adhoc = searchResult.getValue({ name: "custrecord_service_freq_day_adhoc", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_current = searchResult.getValue({ name: "custrecord_service_freq_time_current", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_start = searchResult.getValue({ name: "custrecord_service_freq_time_start", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_time_end = searchResult.getValue({ name: "custrecord_service_freq_time_end", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_run_plan_id = searchResult.getValue({ name: "custrecord_service_freq_run_plan", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_operator = searchResult.getValue({ name: "custrecord_service_freq_operator", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_freq_zee = searchResult.getValue({ name: "custrecord_service_freq_franchisee", join: "CUSTRECORD_SERVICE_FREQ_STOP", summary: search.Summary.GROUP}); var service_multiple_operators = searchResult.getValue({ name: "custrecord_multiple_operators", join: "CUSTRECORD_SERVICE_LEG_SERVICE", summary: search.Summary.GROUP}); var street_no_name = null; log.debug({ title: 'service_leg_id', details: service_leg_id }); try { // statements if (!isNullorEmpty(service_freq_run_plan_id)) { log.debug({ title: 'service_freq_run_plan_id', details: service_freq_run_plan_id }) var run_plan_record = record.load({ id: service_freq_run_plan_id, type: 'customrecord_run_plan' }) var run_plan_inactive = run_plan_record.getValue({ fieldId: 'isinactive'}); log.debug({ title: 'run_plan_inactive ?', details: run_plan_inactive }) var serviceLegRecord = record.load({ type: 'customrecord_service_freq', id: service_freq_id }); var weekOfDay = serviceLegRecord.getValue({ fieldId: days_of_week2[day + 1]}); log.debug({ title: 'weekOfDay', details: weekOfDay }) if (weekOfDay == false && service_freq_adhoc == false) { } else { if (run_plan_inactive == false) { log.audit({ title: 'Run Plan Inactive = False' }); if (isNullorEmpty(service_leg_addr_subdwelling) && !isNullorEmpty(service_leg_addr_st_num)) { street_no_name = service_leg_addr_st_num; } else if (!isNullorEmpty(service_leg_addr_subdwelling) && isNullorEmpty(service_leg_addr_st_num)) { street_no_name = service_leg_addr_subdwelling; } else { street_no_name = service_leg_addr_subdwelling + ', ' + service_leg_addr_st_num; } service_leg_addr_st_num = street_no_name; if (old_service_id != service_id) { var usage_loopstart_cust = ctx.getRemainingUsage(); log.debug({ title: 'usage_loopstart_cust', details: usage_loopstart_cust }) log.debug({ title: 'usage_threshold', details: usage_threshold }) if (usage_loopstart_cust < usage_threshold) { var params = { custscript_rp_prev_deployment_create_app: ctx.deploymentId, custscript_rp_old_service_id_create_app: old_service_id, custscript_rp_app_job_group_id_create_app: app_job_group_id2 } reschedule = task.create({ taskType: task.TaskType.SCHEDULED_SCRIPT, scriptId: 'customscript_ss_create_app_jobs_2', deploymentId: 'customdeploy_ss_create_app_jobs_2', params: params }); log.audit({​​​​​ title: 'Reschedule Return - IN LOOP' }); var rescheduled = reschedule.submit(); // if (task.checkStatus({​​​​​ taskId: reschedule}​​​​​) == false) {​​​​​ // exit = true; // return false; // }​​​​​ } createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id2, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators); var service_leg_record = record.load({ id: service_leg_id, type: 'customrecord_service_leg' }) service_leg_record.setValue({ fieldId: 'custrecord_app_ser_leg_daily_job_create', value: 1}); var service = service_leg_record.save(); log.audit({ title: 'Service Leg - Saved', details: service }) app_job_group_id2 = createAppJobGroup(service_leg_service_text, service_leg_customer, service_leg_zee, service_id); } else { createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id2, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators); var service_leg_record = record.load({ id: service_leg_id, type: 'customrecord_service_leg' }) service_leg_record.setValue({ fieldId: 'custrecord_app_ser_leg_daily_job_create', value: 1}); service_leg_record.save(); } } log.audit({ title: 'Finised Run Plan' }); } } } catch (e) { // statements var body = 'Error on one of the following: \n'; body += 'Service Leg ID: ' + service_leg_id + '\n'; body += 'Service Leg Freq ID: ' + service_freq_id + '\n'; body += 'Run Plan: ' + service_freq_run_plan_id + '\n'; body += 'e: ' + e + '\n'; email.send({ author: 112209, recipients: 'PI:EMAIL:[email protected]_PI', subject: 'Create App Jobs', body: body}) log.debug({ title: 'ERROR', details: body }); } old_service_id = service_id; count++; return true; }); log.audit({ title: 'Total Count for ' + zee_name, details: count }); if (exit == false) { var zee_record = record.load({type: 'partner', id: zee_id}); zee_record.setValue({ fieldId: 'custentity_zee_app_job_created', value: 1}); // REMEMBER TO UNCOMMENT zee_record.save(); reschedule = task.create({ taskType: task.TaskType.SCHEDULED_SCRIPT, scriptId: 'customscript_ss_create_app_jobs_2', deploymentId: 'customdeploy_ss_create_app_jobs_2' }); log.emergency({​​​​​ title: 'Reschedule Return - END LOOP' }); var rescheduled = reschedule.submit(); // if (task.checkStatus({​​​​​ taskId: rescheduled}​​​​​) == false) {​​​​​ // // exit = true; // log.debug({ // title: 'Reschedule Status False' // }); // return false; // }​​​​​ } // To remove or not too remove?!?!? // return true; }); } function createAppJobGroup(service_leg_service_text, service_leg_customer, service_leg_zee, service_id) { var app_job_group_rec = record.create({ type: 'customrecord_jobgroup' }); log.audit({ title: 'Create Jobs Group Activated', details: app_job_group_rec }); app_job_group_rec.setValue({ fieldId: 'name', value: service_leg_service_text + '_' + date_of_week}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_ref', value: service_leg_service_text + '_' + date_of_week}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_customer', value: service_leg_customer}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_franchisee', value: service_leg_zee}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_service', value: service_id}); app_job_group_rec.setValue({ fieldId: 'custrecord_jobgroup_status', value: 4}); var app_job_group_id = app_job_group_rec.save(); return app_job_group_id; } function createAppJobs(service_leg_id, service_leg_customer, service_leg_name, service_id, service_price, service_freq_time_current, service_freq_time_end, service_freq_time_start, service_leg_no, app_job_group_id, service_leg_addr_st_num, service_leg_addr_suburb, service_leg_addr_state, service_leg_addr_postcode, service_leg_addr_lat, service_leg_addr_lon, service_leg_zee, service_id, service_leg_notes, service_freq_run_plan_id, service_leg_location_type, service_freq_adhoc, service_leg_customer_text, service_multiple_operators) { var app_job_rec = record.create({ type: 'customrecord_job' }); log.audit({ title: 'Create Jobs Function Activated', details: app_job_rec }); app_job_rec.setValue({ fieldId: 'custrecord_job_franchisee', value: service_leg_zee}); log.audit({ title: 'Adhoc Value', details: service_freq_adhoc }); // if (service_freq_adhoc == 'T') { if (service_freq_adhoc == true) { if (service_leg_location_type == 2) { app_job_rec.setValue({ fieldId:'custrecord_app_job_stop_name', value: 'ADHOC - ' + service_leg_name + ' - ' + service_leg_customer_text}); } else { app_job_rec.setValue({ fieldId:'custrecord_app_job_stop_name', value: 'ADHOC - ' + service_leg_name}); } } else { app_job_rec.setValue({ fieldId: 'custrecord_app_job_stop_name', value: service_leg_name}); } app_job_rec.setValue({ fieldId: 'custrecord_job_customer', value: service_leg_customer}); app_job_rec.setValue({ fieldId: 'custrecord_job_source', value: 6}); app_job_rec.setValue({ fieldId: 'custrecord_job_service', value: service_id}); app_job_rec.setValue({ fieldId: 'custrecord_job_service_price', value: service_price}); app_job_rec.setValue({ fieldId: 'custrecord_job_stop', value: service_leg_id}); app_job_rec.setValue({ fieldId: 'custrecord159', value: service_leg_id}); app_job_rec.setValue({ fieldId: 'custrecord_job_status', value: 1}); var new_date_of_week = format.parse({ type: format.Type.DATE, value: date_of_week }); app_job_rec.setValue({ fieldId: 'custrecord_job_date_scheduled', value: new_date_of_week}); var convert_curr_arr = convertTo24Hour(service_freq_time_current); var curr_arr = convert_curr_arr.split(':'); var curr_1 = parseInt(curr_arr[0]); var curr_2 = parseInt(curr_arr[1]); var currTimeVar = new Date (); currTimeVar.setHours(curr_1, curr_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled', value: currTimeVar}); var convert_end_arr = convertTo24Hour(service_freq_time_end); var end_arr = convert_end_arr.split(':'); var end_1 = parseInt(end_arr[0]); var end_2 = parseInt(end_arr[1]); var endTimeVar = new Date (); endTimeVar.setHours(end_1, end_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled_after', value: endTimeVar}); var convert_start_arr = convertTo24Hour(service_freq_time_start); var start_arr = convert_start_arr.split(':'); var start_1 = parseInt(start_arr[0]); var start_2 = parseInt(start_arr[1]); var startTimeVar = new Date ();; startTimeVar.setHours(start_1, start_2, 0, 0); app_job_rec.setValue({ fieldId: 'custrecord_job_time_scheduled_before', value: startTimeVar}); app_job_rec.setValue({ fieldId: 'custrecord_job_service_leg', value: service_leg_no}); app_job_rec.setValue({ fieldId: 'custrecord_job_group', value: app_job_group_id}); // app_job_rec.setValue({ fieldId: 'custrecord_job_group_status'}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_st_name_no', value: service_leg_addr_st_num}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_suburb', value: service_leg_addr_suburb}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_state', value: service_leg_addr_state}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_post_code', value: service_leg_addr_postcode}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_lat', value: service_leg_addr_lat}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_lon', value: service_leg_addr_lon}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_notes', value: service_leg_notes}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_run', value: service_freq_run_plan_id}); app_job_rec.setValue({ fieldId: 'custrecord_app_job_location_type', value: service_leg_location_type}); app_job_rec.setValue({ fieldId: 'custrecord_job_multiple_operators', value: service_multiple_operators}); // log.audit({ // title: 'Create App Jobs Completed', // }) var create_app_id = app_job_rec.save(); log.audit({ title: 'Create_App Saved with ID', details: create_app_id }); } function convertTo24Hour(time) { // nlapiLogExecution('DEBUG', 'time', time); var hours = parseInt(time.substr(0, 2)); if (time.indexOf('AM') != -1 && hours == 12) { time = time.replace('12', '0'); } if (time.indexOf('AM') != -1 && hours < 10) { time = time.replace(hours, ('0' + hours)); } if (time.indexOf('PM') != -1 && hours < 12) { time = time.replace(hours, (hours + 12)); } return time.replace(/( AM| PM)/, ''); } function onTimeChange(value) { if (!isNullorEmpty(value)) { var timeSplit = value.split(':'), hours, minutes, meridian; hours = timeSplit[0]; minutes = timeSplit[1]; if (hours > 12) { meridian = 'PM'; hours -= 12; } else if (hours < 12) { meridian = 'AM'; if (hours == 0) { hours = 12; } } else { meridian = 'PM'; } return (hours + ':' + minutes + ' ' + meridian); } } function isNullorEmpty(val) { if (val == '' || val == null) { return true; } else { return false; } } return { execute: main } });
/** * @NApiVersion 2.0 * @NScriptType Suitelet * Author: Ankith Ravindran * Created on: Wed Apr 19 2023 * Modified on: Wed Apr 19 2023 09:02:52 * SuiteScript Version: 2.0 * Description: Customer cancellation page. * * Copyright (c) 2023 MailPlus Pty. Ltd. */ define(['N/ui/serverWidget', 'N/runtime', 'N/search', 'N/record', 'N/log', 'N/redirect', 'N/error', 'N/currentRecord', 'N/file', 'N/http', 'N/email', 'N/format'], function (ui, runtime, search, record, log, redirect, error, currentRecord, file, http, email, format) { var zee = 0; var role = 0; var baseURL = 'https://1048144.app.netsuite.com'; if (runtime.EnvType == "SANDBOX") { baseURL = 'https://1048144-sb3.app.netsuite.com'; } role = runtime.getCurrentUser().role; if (role == 1000) { zee = runtime.getCurrentUser().id; } else if (role == 3) { //Administrator zee = 6; //test } else if (role == 1032) { // System Support zee = 425904; //test-AR } function onRequest(context) { var type = 'create'; if (context.request.method === 'GET') { var customer_id = null; var customer_record; var entityid; var companyName = ''; type = context.request.parameters.type; customer_id = context.request.parameters.custid; var customer_record = record.load({ type: record.Type.CUSTOMER, id: customer_id, isDynamic: true }); entityid = customer_record.getValue({ fieldId: 'entityid' }); companyName = customer_record.getValue({ fieldId: 'companyname' }); zee = customer_record.getValue({ fieldId: 'partner' }); var form = ui.createForm({ title: 'Customer Cancellation: <a href="' + baseURL + '/app/common/entity/custjob.nl?id=' + customer_id + '">' + entityid + '</a> ' + companyName }); if (!isNullorEmpty(zee)) { var zeeRecord = record.load({ type: record.Type.PARTNER, id: zee, isDynamic: true }); var franchisee_name = zeeRecord.getValue({ fieldId: 'companyname' }); zee_main_contact_name = zeeRecord.getValue({ fieldId: 'custentity3' }); zee_email = zeeRecord.getValue({ fieldId: 'email' }); zee_main_contact_phone = zeeRecord.getValue({ fieldId: 'custentity2' }); zee_abn = zeeRecord.getValue({ fieldId: 'custentity_abn_franchiserecord' }); } //Customer Status customer_status_id = customer_record.getValue({ fieldId: 'entitystatus' }); // Customer Franchisee Text zeeText = customer_record.getText({ fieldId: 'partner' }); /** * Description - To add all the API's to the begining of the page */ var inlineHtml = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"><script src="//code.jquery.com/jquery-1.11.0.min.js"></script><link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"><link href="//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"><script src="//netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script><link rel="stylesheet" href="https://1048144.app.netsuite.com/core/media/media.nl?id=2060796&c=1048144&h=9ee6accfd476c9cae718&_xt=.css"/><script src="https://1048144.app.netsuite.com/core/media/media.nl?id=2060797&c=1048144&h=ef2cda20731d146b5e98&_xt=.js"></script><link type="text/css" rel="stylesheet" href="https://1048144.app.netsuite.com/core/media/media.nl?id=2090583&c=1048144&h=a0ef6ac4e28f91203dfe&_xt=.css">'; inlineHtml += '<div class="container" style="padding-top: 3%;"><div id="alert" class="alert alert-danger fade in"></div></div>'; // Load DataTables inlineHtml += '<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">'; inlineHtml += '<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>'; form.addField({ id: 'upload_file_1', label: 'SERVICE CANCELLATION PROOF - PDF FILE ONLY', type: ui.FieldType.FILE }).updateLayoutType({ layoutType: ui.FieldLayoutType.OUTSIDEBELOW }).isMandatory = true; inlineHtml += '<div class="form-group container open_invoices requester_header">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 heading2">'; inlineHtml += '<h4><span class="label label-default col-xs-12" style="background-color: #095c7b;">SERVICE CANCELLATION DETAILS</span></h4>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container date_effective_section">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 "><div class="input-group"><span class="input-group-addon">DATE EFFECTIVE <span class="mandatory" style="color:red">*</span></span><input type="date" id="date_effective" value="" class="form-control date_effective"/></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</select></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container cancel_reason_div ">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-4 cancel_reason"><div class="input-group"><span class="input-group-addon" id="cancel_reason_text">CANCELATION REASON <span class="mandatory" style="color:red">*</span></span><select id="cancel_reason" class="form-control cancel_reason" ><option></option>'; var industry_search = search.create({ type: 'customlist58', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '<div class="col-xs-4 cancel_notice"><div class="input-group"><span class="input-group-addon" id="cancel_notice_text">CANCELATION NOTICE <span class="mandatory" style="color:red">*</span></span><select id="cancel_notice" class="form-control cancel_notice" ><option></option>'; var industry_search = search.create({ type: 'customlist_cancellation_notice', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '<div class="col-xs-4 cancel_comp"><div class="input-group"><span class="input-group-addon" id="cancel_comp_text">CANCELLATION COMPETITOR</span><select id="cancel_comp" class="form-control cancel_comp" ><option></option>'; var industry_search = search.create({ type: 'customlist33', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container note_section">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 note"><div class="input-group"><span class="input-group-addon" id="note_text">NOTE </span><textarea id="note" class="form-control note" rows="4" cols="50" /></textarea></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; // inlineHtml += openInvoicesSection(); form.addField({ id: 'custpage_customer_id', type: ui.FieldType.TEXT, label: 'Customer ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = parseInt(customer_id); form.addField({ id: 'custpage_customer_entityid', type: ui.FieldType.TEXT, label: 'Customer ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = entityid; form.addField({ id: 'custpage_customer_franchisee', type: ui.FieldType.TEXT, label: 'Franchisee ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = zee; form.addField({ id: 'custpage_note', type: ui.FieldType.TEXT, label: 'Note' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_email_body', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_email_subject', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_sale_type', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_send_to', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addSubmitButton({ label: 'Submit' }); form.addField({ id: 'preview_table', label: 'inlinehtml', type: 'inlinehtml' }).updateLayoutType({ layoutType: ui.FieldLayoutType.STARTROW }).defaultValue = inlineHtml; form.addResetButton({ id: 'reset', label: 'Reset', functionName: 'onclick_reset()' }); form.addButton({ id: 'back', label: 'Back', functionName: 'onclick_back()' }); form.clientScriptFileId = 6332354; context.response.writePage(form); } else { var customerId = context.request.parameters.custpage_customer_id; var fileObj = context.request.files.upload_file_1; var note = context.request.parameters.custpage_note; var emailBody = context.request.parameters.custpage_email_body; var emailSubject = context.request.parameters.custpage_email_subject; var zee_email = context.request.parameters.custpage_send_to; log.debug({ title: 'customerId', details: customerId }); var proofid = null; if (!isNullorEmpty(fileObj)) { fileObj.folder = 3630868; var file_type = fileObj.fileType; if (file_type == 'PDF') { file_type == 'pdf'; var file_name = getDatePDF() + '_' + parseInt(customerId) + '.' + file_type; var file_name = getDatePDF() + '_service_change_notification_' + parseInt(customerId) + '.' + file_type; } fileObj.name = file_name; if (file_type == 'PDF') { // Create file and upload it to the file cabinet. proofid = fileObj.save(); } else { error.create({ message: 'Must be in PDF format', name: 'PDF_ERROR', notifyOff: true }); } } var customer_record = record.load({ type: record.Type.CUSTOMER, id: parseInt(customerId), isDynamic: true }); var fileEmailAttachObj = null; if (!isNullorEmpty(proofid)) { customer_record.setValue({ fieldId: 'custentity_cancel_proof', value: proofid }); fileEmailAttachObj = file.load({ id: proofid }); } customer_record.save(); // var userNoteRecord = record.create({ // type: record.Type.NOTE, // isDynamic: true // }); // userNoteRecord.setValue({ // fieldId: 'entity', // value: customer_id // }); // userNoteRecord.setValue({ // fieldId: 'title', // value: 'Cancellation' // }); // userNoteRecord.setValue({ // fieldId: 'direction', // value: 1 // }); // userNoteRecord.setValue({ // fieldId: 'notetype', // value: 3 // }); // userNoteRecord.setValue({ // fieldId: 'author', // value: runtime.getCurrentUser().id // }); // userNoteRecord.setValue({ // fieldId: 'notedate', // value: getDateStoreNS() // }); // userNoteRecord.setValue({ // fieldId: 'note', // value: note // }); // var userNoteRecordId = userNoteRecord.save(); if (!isNullorEmpty(fileEmailAttachObj)) { email.send({ author: 112209, recipients: [zee_email], subject: emailSubject, body: emailBody, cc: [ '[email protected]', '[email protected]', '[email protected]' ], attachments: [fileEmailAttachObj], relatedRecords: { entityId: parseInt(customerId), } }); } else { email.send({ author: 112209, recipients: [zee_email], subject: emailSubject, body: emailBody, cc: [ '[email protected]', '[email protected]', '[email protected]' ], relatedRecords: { entityId: parseInt(customerId), } }); } context.response.sendRedirect({ type: http.RedirectType.RECORD, identifier: record.Type.CUSTOMER, id: parseInt(customerId) }); } } /** * A Datatable displaying the open invoices of the customer * @param {Number} ticket_id * @param {String} selector_type * @return {String} inlineHtml */ function openInvoicesSection() { var hide_class_section = ''; // Open invoices header var inlineHtml = '<div class="form-group container open_invoices open_invoices_header ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 heading2">'; inlineHtml += '<h4><span class="label label-default col-xs-12" style="background-color: #095c7b;">OPEN INVOICES</span></h4>'; inlineHtml += '</div></div></div>'; // Open invoices dropdown field inlineHtml += '<div class="form-group container open_invoices invoices_dropdown ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 invoices_dropdown_div">'; inlineHtml += '<div class="input-group">'; inlineHtml += '<span class="input-group-addon" id="invoices_dropdown_text">INVOICE STATUS</span>'; inlineHtml += '<select id="invoices_dropdown" class="form-control">'; inlineHtml += '<option value="open" selected>Open</option>'; inlineHtml += '<option value="paidInFull">Paid In Full (last 3 months)</option>'; inlineHtml += '</select>'; inlineHtml += '</div></div></div></div>'; // Open Invoices Datatable inlineHtml += '<div class="form-group container open_invoices open_invoices_table ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12" id="open_invoice_dt_div">'; // It is inserted as inline html in the script mp_cl_open_ticket inlineHtml += '</div></div></div>'; return inlineHtml; } function getDateStoreNS() { var date = new Date(); if (date.getHours() > 6) { date.setDate(date.getDate() + 1); } format.format({ value: date, type: format.Type.DATE, timezone: format.Timezone.AUSTRALIA_SYDNEY }) return date; } function getDatePDF() { var date = (new Date()); // if (date.getHours() > 6) { // date = nlapiAddDays(date, 1); // } // date.setHours(date.getHours() + 17); var date_string = date.getFullYear() + '' + (date.getMonth() + 1) + '' + date.getDate() + '_' + date.getHours() + '' + date.getMinutes(); return date_string; } function pad(s) { return (s < 10) ? '0' + s : s; } function GetFormattedDate(stringDate) { var todayDate = nlapiStringToDate(stringDate); var month = pad(todayDate.getMonth() + 1); var day = pad(todayDate.getDate()); var year = (todayDate.getFullYear()); return year + "-" + month + "-" + day; } function isNullorEmpty(val) { if (val == '' || val == null) { return true; } else { return false; } } return { onRequest: onRequest }; });
1,115
[{"tag": "EMAIL", "value": "[email protected]", "start": 17658, "end": 17688}, {"tag": "EMAIL", "value": "[email protected]", "start": 17720, "end": 17746}, {"tag": "EMAIL", "value": "[email protected]", "start": 17778, "end": 17805}, {"tag": "EMAIL", "value": "[email protected]", "start": 18340, "end": 18370}, {"tag": "EMAIL", "value": "[email protected]", "start": 18402, "end": 18428}, {"tag": "EMAIL", "value": "[email protected]", "start": 18460, "end": 18487}]
true
6
/** * @NApiVersion 2.0 * @NScriptType Suitelet * Author: Ankith Ravindran * Created on: Wed Apr 19 2023 * Modified on: Wed Apr 19 2023 09:02:52 * SuiteScript Version: 2.0 * Description: Customer cancellation page. * * Copyright (c) 2023 MailPlus Pty. Ltd. */ define(['N/ui/serverWidget', 'N/runtime', 'N/search', 'N/record', 'N/log', 'N/redirect', 'N/error', 'N/currentRecord', 'N/file', 'N/http', 'N/email', 'N/format'], function (ui, runtime, search, record, log, redirect, error, currentRecord, file, http, email, format) { var zee = 0; var role = 0; var baseURL = 'https://1048144.app.netsuite.com'; if (runtime.EnvType == "SANDBOX") { baseURL = 'https://1048144-sb3.app.netsuite.com'; } role = runtime.getCurrentUser().role; if (role == 1000) { zee = runtime.getCurrentUser().id; } else if (role == 3) { //Administrator zee = 6; //test } else if (role == 1032) { // System Support zee = 425904; //test-AR } function onRequest(context) { var type = 'create'; if (context.request.method === 'GET') { var customer_id = null; var customer_record; var entityid; var companyName = ''; type = context.request.parameters.type; customer_id = context.request.parameters.custid; var customer_record = record.load({ type: record.Type.CUSTOMER, id: customer_id, isDynamic: true }); entityid = customer_record.getValue({ fieldId: 'entityid' }); companyName = customer_record.getValue({ fieldId: 'companyname' }); zee = customer_record.getValue({ fieldId: 'partner' }); var form = ui.createForm({ title: 'Customer Cancellation: <a href="' + baseURL + '/app/common/entity/custjob.nl?id=' + customer_id + '">' + entityid + '</a> ' + companyName }); if (!isNullorEmpty(zee)) { var zeeRecord = record.load({ type: record.Type.PARTNER, id: zee, isDynamic: true }); var franchisee_name = zeeRecord.getValue({ fieldId: 'companyname' }); zee_main_contact_name = zeeRecord.getValue({ fieldId: 'custentity3' }); zee_email = zeeRecord.getValue({ fieldId: 'email' }); zee_main_contact_phone = zeeRecord.getValue({ fieldId: 'custentity2' }); zee_abn = zeeRecord.getValue({ fieldId: 'custentity_abn_franchiserecord' }); } //Customer Status customer_status_id = customer_record.getValue({ fieldId: 'entitystatus' }); // Customer Franchisee Text zeeText = customer_record.getText({ fieldId: 'partner' }); /** * Description - To add all the API's to the begining of the page */ var inlineHtml = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"><script src="//code.jquery.com/jquery-1.11.0.min.js"></script><link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"><link href="//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"><script src="//netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script><link rel="stylesheet" href="https://1048144.app.netsuite.com/core/media/media.nl?id=2060796&c=1048144&h=9ee6accfd476c9cae718&_xt=.css"/><script src="https://1048144.app.netsuite.com/core/media/media.nl?id=2060797&c=1048144&h=ef2cda20731d146b5e98&_xt=.js"></script><link type="text/css" rel="stylesheet" href="https://1048144.app.netsuite.com/core/media/media.nl?id=2090583&c=1048144&h=a0ef6ac4e28f91203dfe&_xt=.css">'; inlineHtml += '<div class="container" style="padding-top: 3%;"><div id="alert" class="alert alert-danger fade in"></div></div>'; // Load DataTables inlineHtml += '<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">'; inlineHtml += '<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>'; form.addField({ id: 'upload_file_1', label: 'SERVICE CANCELLATION PROOF - PDF FILE ONLY', type: ui.FieldType.FILE }).updateLayoutType({ layoutType: ui.FieldLayoutType.OUTSIDEBELOW }).isMandatory = true; inlineHtml += '<div class="form-group container open_invoices requester_header">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 heading2">'; inlineHtml += '<h4><span class="label label-default col-xs-12" style="background-color: #095c7b;">SERVICE CANCELLATION DETAILS</span></h4>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container date_effective_section">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 "><div class="input-group"><span class="input-group-addon">DATE EFFECTIVE <span class="mandatory" style="color:red">*</span></span><input type="date" id="date_effective" value="" class="form-control date_effective"/></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</select></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container cancel_reason_div ">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-4 cancel_reason"><div class="input-group"><span class="input-group-addon" id="cancel_reason_text">CANCELATION REASON <span class="mandatory" style="color:red">*</span></span><select id="cancel_reason" class="form-control cancel_reason" ><option></option>'; var industry_search = search.create({ type: 'customlist58', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '<div class="col-xs-4 cancel_notice"><div class="input-group"><span class="input-group-addon" id="cancel_notice_text">CANCELATION NOTICE <span class="mandatory" style="color:red">*</span></span><select id="cancel_notice" class="form-control cancel_notice" ><option></option>'; var industry_search = search.create({ type: 'customlist_cancellation_notice', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '<div class="col-xs-4 cancel_comp"><div class="input-group"><span class="input-group-addon" id="cancel_comp_text">CANCELLATION COMPETITOR</span><select id="cancel_comp" class="form-control cancel_comp" ><option></option>'; var industry_search = search.create({ type: 'customlist33', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container note_section">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 note"><div class="input-group"><span class="input-group-addon" id="note_text">NOTE </span><textarea id="note" class="form-control note" rows="4" cols="50" /></textarea></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; // inlineHtml += openInvoicesSection(); form.addField({ id: 'custpage_customer_id', type: ui.FieldType.TEXT, label: 'Customer ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = parseInt(customer_id); form.addField({ id: 'custpage_customer_entityid', type: ui.FieldType.TEXT, label: 'Customer ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = entityid; form.addField({ id: 'custpage_customer_franchisee', type: ui.FieldType.TEXT, label: 'Franchisee ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = zee; form.addField({ id: 'custpage_note', type: ui.FieldType.TEXT, label: 'Note' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_email_body', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_email_subject', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_sale_type', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_send_to', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addSubmitButton({ label: 'Submit' }); form.addField({ id: 'preview_table', label: 'inlinehtml', type: 'inlinehtml' }).updateLayoutType({ layoutType: ui.FieldLayoutType.STARTROW }).defaultValue = inlineHtml; form.addResetButton({ id: 'reset', label: 'Reset', functionName: 'onclick_reset()' }); form.addButton({ id: 'back', label: 'Back', functionName: 'onclick_back()' }); form.clientScriptFileId = 6332354; context.response.writePage(form); } else { var customerId = context.request.parameters.custpage_customer_id; var fileObj = context.request.files.upload_file_1; var note = context.request.parameters.custpage_note; var emailBody = context.request.parameters.custpage_email_body; var emailSubject = context.request.parameters.custpage_email_subject; var zee_email = context.request.parameters.custpage_send_to; log.debug({ title: 'customerId', details: customerId }); var proofid = null; if (!isNullorEmpty(fileObj)) { fileObj.folder = 3630868; var file_type = fileObj.fileType; if (file_type == 'PDF') { file_type == 'pdf'; var file_name = getDatePDF() + '_' + parseInt(customerId) + '.' + file_type; var file_name = getDatePDF() + '_service_change_notification_' + parseInt(customerId) + '.' + file_type; } fileObj.name = file_name; if (file_type == 'PDF') { // Create file and upload it to the file cabinet. proofid = fileObj.save(); } else { error.create({ message: 'Must be in PDF format', name: 'PDF_ERROR', notifyOff: true }); } } var customer_record = record.load({ type: record.Type.CUSTOMER, id: parseInt(customerId), isDynamic: true }); var fileEmailAttachObj = null; if (!isNullorEmpty(proofid)) { customer_record.setValue({ fieldId: 'custentity_cancel_proof', value: proofid }); fileEmailAttachObj = file.load({ id: proofid }); } customer_record.save(); // var userNoteRecord = record.create({ // type: record.Type.NOTE, // isDynamic: true // }); // userNoteRecord.setValue({ // fieldId: 'entity', // value: customer_id // }); // userNoteRecord.setValue({ // fieldId: 'title', // value: 'Cancellation' // }); // userNoteRecord.setValue({ // fieldId: 'direction', // value: 1 // }); // userNoteRecord.setValue({ // fieldId: 'notetype', // value: 3 // }); // userNoteRecord.setValue({ // fieldId: 'author', // value: runtime.getCurrentUser().id // }); // userNoteRecord.setValue({ // fieldId: 'notedate', // value: getDateStoreNS() // }); // userNoteRecord.setValue({ // fieldId: 'note', // value: note // }); // var userNoteRecordId = userNoteRecord.save(); if (!isNullorEmpty(fileEmailAttachObj)) { email.send({ author: 112209, recipients: [zee_email], subject: emailSubject, body: emailBody, cc: [ '[email protected]', '[email protected]', '[email protected]' ], attachments: [fileEmailAttachObj], relatedRecords: { entityId: parseInt(customerId), } }); } else { email.send({ author: 112209, recipients: [zee_email], subject: emailSubject, body: emailBody, cc: [ '[email protected]', '[email protected]', '[email protected]' ], relatedRecords: { entityId: parseInt(customerId), } }); } context.response.sendRedirect({ type: http.RedirectType.RECORD, identifier: record.Type.CUSTOMER, id: parseInt(customerId) }); } } /** * A Datatable displaying the open invoices of the customer * @param {Number} ticket_id * @param {String} selector_type * @return {String} inlineHtml */ function openInvoicesSection() { var hide_class_section = ''; // Open invoices header var inlineHtml = '<div class="form-group container open_invoices open_invoices_header ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 heading2">'; inlineHtml += '<h4><span class="label label-default col-xs-12" style="background-color: #095c7b;">OPEN INVOICES</span></h4>'; inlineHtml += '</div></div></div>'; // Open invoices dropdown field inlineHtml += '<div class="form-group container open_invoices invoices_dropdown ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 invoices_dropdown_div">'; inlineHtml += '<div class="input-group">'; inlineHtml += '<span class="input-group-addon" id="invoices_dropdown_text">INVOICE STATUS</span>'; inlineHtml += '<select id="invoices_dropdown" class="form-control">'; inlineHtml += '<option value="open" selected>Open</option>'; inlineHtml += '<option value="paidInFull">Paid In Full (last 3 months)</option>'; inlineHtml += '</select>'; inlineHtml += '</div></div></div></div>'; // Open Invoices Datatable inlineHtml += '<div class="form-group container open_invoices open_invoices_table ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12" id="open_invoice_dt_div">'; // It is inserted as inline html in the script mp_cl_open_ticket inlineHtml += '</div></div></div>'; return inlineHtml; } function getDateStoreNS() { var date = new Date(); if (date.getHours() > 6) { date.setDate(date.getDate() + 1); } format.format({ value: date, type: format.Type.DATE, timezone: format.Timezone.AUSTRALIA_SYDNEY }) return date; } function getDatePDF() { var date = (new Date()); // if (date.getHours() > 6) { // date = nlapiAddDays(date, 1); // } // date.setHours(date.getHours() + 17); var date_string = date.getFullYear() + '' + (date.getMonth() + 1) + '' + date.getDate() + '_' + date.getHours() + '' + date.getMinutes(); return date_string; } function pad(s) { return (s < 10) ? '0' + s : s; } function GetFormattedDate(stringDate) { var todayDate = nlapiStringToDate(stringDate); var month = pad(todayDate.getMonth() + 1); var day = pad(todayDate.getDate()); var year = (todayDate.getFullYear()); return year + "-" + month + "-" + day; } function isNullorEmpty(val) { if (val == '' || val == null) { return true; } else { return false; } } return { onRequest: onRequest }; });
true
/** * @NApiVersion 2.0 * @NScriptType Suitelet * Author: Ankith Ravindran * Created on: Wed Apr 19 2023 * Modified on: Wed Apr 19 2023 09:02:52 * SuiteScript Version: 2.0 * Description: Customer cancellation page. * * Copyright (c) 2023 MailPlus Pty. Ltd. */ define(['N/ui/serverWidget', 'N/runtime', 'N/search', 'N/record', 'N/log', 'N/redirect', 'N/error', 'N/currentRecord', 'N/file', 'N/http', 'N/email', 'N/format'], function (ui, runtime, search, record, log, redirect, error, currentRecord, file, http, email, format) { var zee = 0; var role = 0; var baseURL = 'https://1048144.app.netsuite.com'; if (runtime.EnvType == "SANDBOX") { baseURL = 'https://1048144-sb3.app.netsuite.com'; } role = runtime.getCurrentUser().role; if (role == 1000) { zee = runtime.getCurrentUser().id; } else if (role == 3) { //Administrator zee = 6; //test } else if (role == 1032) { // System Support zee = 425904; //test-AR } function onRequest(context) { var type = 'create'; if (context.request.method === 'GET') { var customer_id = null; var customer_record; var entityid; var companyName = ''; type = context.request.parameters.type; customer_id = context.request.parameters.custid; var customer_record = record.load({ type: record.Type.CUSTOMER, id: customer_id, isDynamic: true }); entityid = customer_record.getValue({ fieldId: 'entityid' }); companyName = customer_record.getValue({ fieldId: 'companyname' }); zee = customer_record.getValue({ fieldId: 'partner' }); var form = ui.createForm({ title: 'Customer Cancellation: <a href="' + baseURL + '/app/common/entity/custjob.nl?id=' + customer_id + '">' + entityid + '</a> ' + companyName }); if (!isNullorEmpty(zee)) { var zeeRecord = record.load({ type: record.Type.PARTNER, id: zee, isDynamic: true }); var franchisee_name = zeeRecord.getValue({ fieldId: 'companyname' }); zee_main_contact_name = zeeRecord.getValue({ fieldId: 'custentity3' }); zee_email = zeeRecord.getValue({ fieldId: 'email' }); zee_main_contact_phone = zeeRecord.getValue({ fieldId: 'custentity2' }); zee_abn = zeeRecord.getValue({ fieldId: 'custentity_abn_franchiserecord' }); } //Customer Status customer_status_id = customer_record.getValue({ fieldId: 'entitystatus' }); // Customer Franchisee Text zeeText = customer_record.getText({ fieldId: 'partner' }); /** * Description - To add all the API's to the begining of the page */ var inlineHtml = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"><script src="//code.jquery.com/jquery-1.11.0.min.js"></script><link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"><link href="//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"><script src="//netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script><link rel="stylesheet" href="https://1048144.app.netsuite.com/core/media/media.nl?id=2060796&c=1048144&h=9ee6accfd476c9cae718&_xt=.css"/><script src="https://1048144.app.netsuite.com/core/media/media.nl?id=2060797&c=1048144&h=ef2cda20731d146b5e98&_xt=.js"></script><link type="text/css" rel="stylesheet" href="https://1048144.app.netsuite.com/core/media/media.nl?id=2090583&c=1048144&h=a0ef6ac4e28f91203dfe&_xt=.css">'; inlineHtml += '<div class="container" style="padding-top: 3%;"><div id="alert" class="alert alert-danger fade in"></div></div>'; // Load DataTables inlineHtml += '<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">'; inlineHtml += '<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>'; form.addField({ id: 'upload_file_1', label: 'SERVICE CANCELLATION PROOF - PDF FILE ONLY', type: ui.FieldType.FILE }).updateLayoutType({ layoutType: ui.FieldLayoutType.OUTSIDEBELOW }).isMandatory = true; inlineHtml += '<div class="form-group container open_invoices requester_header">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 heading2">'; inlineHtml += '<h4><span class="label label-default col-xs-12" style="background-color: #095c7b;">SERVICE CANCELLATION DETAILS</span></h4>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container date_effective_section">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 "><div class="input-group"><span class="input-group-addon">DATE EFFECTIVE <span class="mandatory" style="color:red">*</span></span><input type="date" id="date_effective" value="" class="form-control date_effective"/></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</select></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container cancel_reason_div ">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-4 cancel_reason"><div class="input-group"><span class="input-group-addon" id="cancel_reason_text">CANCELATION REASON <span class="mandatory" style="color:red">*</span></span><select id="cancel_reason" class="form-control cancel_reason" ><option></option>'; var industry_search = search.create({ type: 'customlist58', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '<div class="col-xs-4 cancel_notice"><div class="input-group"><span class="input-group-addon" id="cancel_notice_text">CANCELATION NOTICE <span class="mandatory" style="color:red">*</span></span><select id="cancel_notice" class="form-control cancel_notice" ><option></option>'; var industry_search = search.create({ type: 'customlist_cancellation_notice', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '<div class="col-xs-4 cancel_comp"><div class="input-group"><span class="input-group-addon" id="cancel_comp_text">CANCELLATION COMPETITOR</span><select id="cancel_comp" class="form-control cancel_comp" ><option></option>'; var industry_search = search.create({ type: 'customlist33', columns: [{ name: 'name' }, { name: 'internalId' }], filters: ['isinactive', 'is', 'false'] }); industry_search.run().each(function (searchResult) { var listValue = searchResult.getValue('name'); var listID = searchResult.getValue('internalId'); inlineHtml += '<option value="' + listID + '">' + listValue + '</option>'; return true; }); inlineHtml += '</select></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '<div class="form-group container note_section">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 note"><div class="input-group"><span class="input-group-addon" id="note_text">NOTE </span><textarea id="note" class="form-control note" rows="4" cols="50" /></textarea></div></div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; inlineHtml += '</div>'; // inlineHtml += openInvoicesSection(); form.addField({ id: 'custpage_customer_id', type: ui.FieldType.TEXT, label: 'Customer ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = parseInt(customer_id); form.addField({ id: 'custpage_customer_entityid', type: ui.FieldType.TEXT, label: 'Customer ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = entityid; form.addField({ id: 'custpage_customer_franchisee', type: ui.FieldType.TEXT, label: 'Franchisee ID' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }).defaultValue = zee; form.addField({ id: 'custpage_note', type: ui.FieldType.TEXT, label: 'Note' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_email_body', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_email_subject', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_sale_type', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addField({ id: 'custpage_send_to', type: ui.FieldType.TEXT, label: 'Email Body' }).updateDisplayType({ displayType: ui.FieldDisplayType.HIDDEN }) form.addSubmitButton({ label: 'Submit' }); form.addField({ id: 'preview_table', label: 'inlinehtml', type: 'inlinehtml' }).updateLayoutType({ layoutType: ui.FieldLayoutType.STARTROW }).defaultValue = inlineHtml; form.addResetButton({ id: 'reset', label: 'Reset', functionName: 'onclick_reset()' }); form.addButton({ id: 'back', label: 'Back', functionName: 'onclick_back()' }); form.clientScriptFileId = 6332354; context.response.writePage(form); } else { var customerId = context.request.parameters.custpage_customer_id; var fileObj = context.request.files.upload_file_1; var note = context.request.parameters.custpage_note; var emailBody = context.request.parameters.custpage_email_body; var emailSubject = context.request.parameters.custpage_email_subject; var zee_email = context.request.parameters.custpage_send_to; log.debug({ title: 'customerId', details: customerId }); var proofid = null; if (!isNullorEmpty(fileObj)) { fileObj.folder = 3630868; var file_type = fileObj.fileType; if (file_type == 'PDF') { file_type == 'pdf'; var file_name = getDatePDF() + '_' + parseInt(customerId) + '.' + file_type; var file_name = getDatePDF() + '_service_change_notification_' + parseInt(customerId) + '.' + file_type; } fileObj.name = file_name; if (file_type == 'PDF') { // Create file and upload it to the file cabinet. proofid = fileObj.save(); } else { error.create({ message: 'Must be in PDF format', name: 'PDF_ERROR', notifyOff: true }); } } var customer_record = record.load({ type: record.Type.CUSTOMER, id: parseInt(customerId), isDynamic: true }); var fileEmailAttachObj = null; if (!isNullorEmpty(proofid)) { customer_record.setValue({ fieldId: 'custentity_cancel_proof', value: proofid }); fileEmailAttachObj = file.load({ id: proofid }); } customer_record.save(); // var userNoteRecord = record.create({ // type: record.Type.NOTE, // isDynamic: true // }); // userNoteRecord.setValue({ // fieldId: 'entity', // value: customer_id // }); // userNoteRecord.setValue({ // fieldId: 'title', // value: 'Cancellation' // }); // userNoteRecord.setValue({ // fieldId: 'direction', // value: 1 // }); // userNoteRecord.setValue({ // fieldId: 'notetype', // value: 3 // }); // userNoteRecord.setValue({ // fieldId: 'author', // value: runtime.getCurrentUser().id // }); // userNoteRecord.setValue({ // fieldId: 'notedate', // value: getDateStoreNS() // }); // userNoteRecord.setValue({ // fieldId: 'note', // value: note // }); // var userNoteRecordId = userNoteRecord.save(); if (!isNullorEmpty(fileEmailAttachObj)) { email.send({ author: 112209, recipients: [zee_email], subject: emailSubject, body: emailBody, cc: [ 'PI:EMAIL:[email protected]_PI', 'PI:EMAIL:[email protected]_PI', 'PI:EMAIL:[email protected]_PI' ], attachments: [fileEmailAttachObj], relatedRecords: { entityId: parseInt(customerId), } }); } else { email.send({ author: 112209, recipients: [zee_email], subject: emailSubject, body: emailBody, cc: [ 'PI:EMAIL:[email protected]_PI', 'PI:EMAIL:[email protected]_PI', 'PI:EMAIL:[email protected]_PI' ], relatedRecords: { entityId: parseInt(customerId), } }); } context.response.sendRedirect({ type: http.RedirectType.RECORD, identifier: record.Type.CUSTOMER, id: parseInt(customerId) }); } } /** * A Datatable displaying the open invoices of the customer * @param {Number} ticket_id * @param {String} selector_type * @return {String} inlineHtml */ function openInvoicesSection() { var hide_class_section = ''; // Open invoices header var inlineHtml = '<div class="form-group container open_invoices open_invoices_header ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 heading2">'; inlineHtml += '<h4><span class="label label-default col-xs-12" style="background-color: #095c7b;">OPEN INVOICES</span></h4>'; inlineHtml += '</div></div></div>'; // Open invoices dropdown field inlineHtml += '<div class="form-group container open_invoices invoices_dropdown ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12 invoices_dropdown_div">'; inlineHtml += '<div class="input-group">'; inlineHtml += '<span class="input-group-addon" id="invoices_dropdown_text">INVOICE STATUS</span>'; inlineHtml += '<select id="invoices_dropdown" class="form-control">'; inlineHtml += '<option value="open" selected>Open</option>'; inlineHtml += '<option value="paidInFull">Paid In Full (last 3 months)</option>'; inlineHtml += '</select>'; inlineHtml += '</div></div></div></div>'; // Open Invoices Datatable inlineHtml += '<div class="form-group container open_invoices open_invoices_table ' + hide_class_section + '">'; inlineHtml += '<div class="row">'; inlineHtml += '<div class="col-xs-12" id="open_invoice_dt_div">'; // It is inserted as inline html in the script mp_cl_open_ticket inlineHtml += '</div></div></div>'; return inlineHtml; } function getDateStoreNS() { var date = new Date(); if (date.getHours() > 6) { date.setDate(date.getDate() + 1); } format.format({ value: date, type: format.Type.DATE, timezone: format.Timezone.AUSTRALIA_SYDNEY }) return date; } function getDatePDF() { var date = (new Date()); // if (date.getHours() > 6) { // date = nlapiAddDays(date, 1); // } // date.setHours(date.getHours() + 17); var date_string = date.getFullYear() + '' + (date.getMonth() + 1) + '' + date.getDate() + '_' + date.getHours() + '' + date.getMinutes(); return date_string; } function pad(s) { return (s < 10) ? '0' + s : s; } function GetFormattedDate(stringDate) { var todayDate = nlapiStringToDate(stringDate); var month = pad(todayDate.getMonth() + 1); var day = pad(todayDate.getDate()); var year = (todayDate.getFullYear()); return year + "-" + month + "-" + day; } function isNullorEmpty(val) { if (val == '' || val == null) { return true; } else { return false; } } return { onRequest: onRequest }; });
"/**\n * @NApiVersion 2.x\n * @NScriptType Suitelet\n * @NModuleScope SameAccount\n */\ndefine(['N/h(...TRUNCATED)
712
"[{\"tag\": \"EMAIL\", \"value\": \"[email protected]\", \"start\": 2216, \"end\"(...TRUNCATED)
true
2
"/**\n * @NApiVersion 2.x\n * @NScriptType Suitelet\n * @NModuleScope SameAccount\n */\ndefine(['N/h(...TRUNCATED)
true
"/**\n * @NApiVersion 2.x\n * @NScriptType Suitelet\n * @NModuleScope SameAccount\n */\ndefine(['N/h(...TRUNCATED)
"/**\r\n * @NApiVersion 2.1\r\n * @NScriptType Portlet\r\n * @NModuleScope SameAccount\r\n */\r\n\r\(...TRUNCATED)
78
[{"tag": "EMAIL", "value": "[email protected]", "start": 146, "end": 164}]
true
1
"/**\r\n * @NApiVersion 2.1\r\n * @NScriptType Portlet\r\n * @NModuleScope SameAccount\r\n */\r\n\r\(...TRUNCATED)
true
"/**\r\n * @NApiVersion 2.1\r\n * @NScriptType Portlet\r\n * @NModuleScope SameAccount\r\n */\r\n\r\(...TRUNCATED)
"define(['N/search'], function(search) {\n\t/**\n\t * Add Google Map for Address form\n\t * @NApiVer(...TRUNCATED)
418
[{"tag": "EMAIL", "value": "[email protected]", "start": 153, "end": 168}]
true
1
"define(['N/search'], function(search) {\n\t/**\n\t * Add Google Map for Address form\n\t * @NApiVer(...TRUNCATED)
true
"define(['N/search'], function(search) {\n\t/**\n\t * Add Google Map for Address form\n\t * @NApiVer(...TRUNCATED)
"/**\r\n * @NApiVersion 2.0\r\n * @NScriptType Suitelet\r\n * \r\n * Module Description\r\n * \r\n *(...TRUNCATED)
818
"[{\"tag\": \"KEY\", \"value\": \"sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN(...TRUNCATED)
true
6
"/**\r\n * @NApiVersion 2.0\r\n * @NScriptType Suitelet\r\n * \r\n * Module Description\r\n * \r\n *(...TRUNCATED)
true
"/**\r\n * @NApiVersion 2.0\r\n * @NScriptType Suitelet\r\n * \r\n * Module Description\r\n * \r\n *(...TRUNCATED)
"/**\n * @NApiVersion 2.1\n * @NScriptType MapReduceScript\n * @NModuleScope SameAccount\n * @NAmdCo(...TRUNCATED)
785
"[{\"tag\": \"KEY\", \"value\": \"236e41105efcb76877ea5366a475158f573b7575a14e06283729a26ed3e8c5d5\"(...TRUNCATED)
true
3
"/**\n * @NApiVersion 2.1\n * @NScriptType MapReduceScript\n * @NModuleScope SameAccount\n * @NAmdCo(...TRUNCATED)
true
"/**\n * @NApiVersion 2.1\n * @NScriptType MapReduceScript\n * @NModuleScope SameAccount\n * @NAmdCo(...TRUNCATED)
"/**\r\n * @NApiVersion 2.0\r\n * @NScriptType Suitelet\r\n * \r\n * Module Description\r\n * \r\n *(...TRUNCATED)
688
"[{\"tag\": \"KEY\", \"value\": \"sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN(...TRUNCATED)
true
3
"/**\r\n * @NApiVersion 2.0\r\n * @NScriptType Suitelet\r\n * \r\n * Module Description\r\n * \r\n *(...TRUNCATED)
true
"/**\r\n * @NApiVersion 2.0\r\n * @NScriptType Suitelet\r\n * \r\n * Module Description\r\n * \r\n *(...TRUNCATED)
"/**\n * @NApiVersion 2.0\n * @NScriptType MapReduceScript\n */\ndefine(['N/record', 'N/search', 'N/(...TRUNCATED)
496
[{"tag": "EMAIL", "value": "[email protected]", "start": 2993, "end": 3016}]
true
1
"/**\n * @NApiVersion 2.0\n * @NScriptType MapReduceScript\n */\ndefine(['N/record', 'N/search', 'N/(...TRUNCATED)
true
"/**\n * @NApiVersion 2.0\n * @NScriptType MapReduceScript\n */\ndefine(['N/record', 'N/search', 'N/(...TRUNCATED)
"/**\n * @NScriptName Geocoding Script\n * @NApiVersion 2.x\n * @NScriptType Suitelet\n * @NModuleSc(...TRUNCATED)
781
"[{\"tag\": \"KEY\", \"value\": \"AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY\", \"start\": 2080, \"end\(...TRUNCATED)
true
1
"/**\n * @NScriptName Geocoding Script\n * @NApiVersion 2.x\n * @NScriptType Suitelet\n * @NModuleSc(...TRUNCATED)
true
"/**\n * @NScriptName Geocoding Script\n * @NApiVersion 2.x\n * @NScriptType Suitelet\n * @NModuleSc(...TRUNCATED)

Dataset Card for "bigcode-pii-pjj_checks"

More Information needed

Downloads last month
41
Edit dataset card