aaron_tekton
01/28/2020, 2:29 PMN/redirect
? I’m trying to use it and, well, it’s not redirecting.dmashburn3
01/28/2020, 2:31 PMaaron_tekton
01/28/2020, 2:33 PMaaron_tekton
01/28/2020, 2:34 PMconst afterSubmit = scriptContext => {
const inspectionId = 57144;
log.debug( {
title: "Redirecting to customrecord_inspection",
details: inspectionId
} );
_Redirect.toRecord({
type: "customrecord_inspection",
id: inspectionId
});
};
aaron_tekton
01/28/2020, 2:35 PMdmashburn3
01/28/2020, 2:36 PMaaron_tekton
01/28/2020, 2:36 PMaaron_tekton
01/28/2020, 2:36 PMdmashburn3
01/28/2020, 2:37 PMaaron_tekton
01/28/2020, 2:37 PMdmashburn3
01/28/2020, 2:38 PMaaron_tekton
01/28/2020, 2:38 PMaaron_tekton
01/28/2020, 2:38 PMaaron_tekton
01/28/2020, 2:38 PMdmashburn3
01/28/2020, 2:39 PMaaron_tekton
01/28/2020, 2:40 PMaaron_tekton
01/28/2020, 2:40 PMdmashburn3
01/28/2020, 2:40 PMdmashburn3
01/28/2020, 2:40 PMdmashburn3
01/28/2020, 2:41 PMaaron_tekton
01/28/2020, 2:41 PMD17339
01/28/2020, 2:41 PMdmashburn3
01/28/2020, 2:41 PMaaron_tekton
01/28/2020, 2:41 PMaaron_tekton
01/28/2020, 2:41 PMdmashburn3
01/28/2020, 2:42 PMsynchronous afterSubmit user events
D17339
01/28/2020, 2:42 PM_Redirect
are you sure on this _Redirect is referred to redirect modul parameteraaron_tekton
01/28/2020, 2:42 PMD17339
01/28/2020, 2:43 PMaaron_tekton
01/28/2020, 2:43 PMaaron_tekton
01/28/2020, 2:43 PMdmashburn3
01/28/2020, 2:44 PMaaron_tekton
01/28/2020, 2:45 PMaaron_tekton
01/28/2020, 2:45 PMdmashburn3
01/28/2020, 2:45 PMredirect.toSearchResults
in a suitelet... which wasn't supported, but worked... except for that it duplicated columnsdmashburn3
01/28/2020, 2:46 PMaaron_tekton
01/28/2020, 2:46 PMD17339
01/28/2020, 2:48 PMaaron_tekton
01/28/2020, 2:50 PMaaron_tekton
01/28/2020, 2:51 PMaaron_tekton
01/28/2020, 2:51 PM/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*
* @typedef {Object} log
* @typedef {Object} util
*
* Author: aaronkoenes
* Date Created: 2020-01-15
*/
define( [
"N/search",
"../Custom Modules/TSS_CM_Extensions",
"./TSS_CM_InspectionDefect",
"../Inspections/TSS_CM_Inspections",
"N/record",
"N/runtime",
"N/redirect"
],
( _Search, _Ext, _InspectionDefect, _Inspections, _Record, _Runtime, _Redirect ) => {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
const beforeLoad = scriptContext => {
// disabled in return object
};
/**
* Function definition to be triggered before record is submitted.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
const beforeSubmit = scriptContext => {
let newRec = scriptContext.newRecord;
const isDelete = scriptContext.type === scriptContext.UserEventType.DELETE;
const isCreate = scriptContext.type === scriptContext.UserEventType.CREATE;
const isXedit = scriptContext.type === scriptContext.UserEventType.XEDIT;
/* Update the AQL if:
* 1) We're creating a new Inspection Defect or
* 2) We're editing the defect field on an exising Inspection Defect
*
* If we're deleting an inspection defect, don't perform this check or
* else scriptContext.oldRecord will throw an error.
*/
let updateAQL = isCreate;
if( !updateAQL && !isDelete ) {
const oldDefect = scriptContext.oldRecord.getValue({
fieldId: "custrecord_inspdef_defect"
});
const newDefect = scriptContext.newRecord.getValue({
fieldId: "custrecord_inspdef_defect"
});
updateAQL = oldDefect !== newDefect;
}
// If this is an XEDIT, load the Inspection Defect record in full.
// This record can only be used to GET data, not to set data that needs
// to be saved once beforeSubmit completes
if( isXedit || isDelete ) {
newRec = _Record.load({
type: _InspectionDefect.RecordId,
id: newRec.id
});
}
/* Check the status of the Inspection associated with this record. If
* it's not in an allowed state, don't save this entry
*/
const inspectionId = newRec.getValue({
fieldId: "custrecord_inspdef_inspection"
});
if( !inspectionId ) {
throw "No inspection was specified";
}
const inspectionStatus = _Search.lookupFields({
type: _Inspections.RecordId,
id: inspectionId,
columns: ["custrecord_insp_status"]
}).custrecord_insp_status;
if( inspectionStatus ) {
const status = inspectionStatus[0].value;
const disallowedInspectionStatuses = [
_Inspections.Status.PAUSED,
_Inspections.Status.CANCELED,
_Inspections.Status.PASSED,
_Inspections.Status.FAILED
];
const editAnytimeUsers = [
_Ext.USERS.AARON_KOENES,
_Ext.USERS.CHRIS_GEARINGER
];
if( _Runtime.getCurrentUser().id.isNoneOf( editAnytimeUsers ) ) {
if( status.isAnyOf( disallowedInspectionStatuses ) ) {
throw "You cannot record a new defect for an " +
"inspection that isn't in progress";
}
}
}
if( updateAQL ) {
const defectID =
newRec.getValue({ fieldId: "custrecord_inspdef_defect" });
const defectAllowedQualityLimit = _InspectionDefect.getAQL( defectID );
scriptContext.newRecord.setValue({
fieldId: "custrecord_inspdef_aql",
value: defectAllowedQualityLimit
});
}
};
/**
* Function definition to be triggered after record is submitted.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
const afterSubmit = scriptContext => {
const inspectionId = "57144";
log.debug( {
title: "Redirecting to customrecord_inspection",
details: inspectionId
} );
_Redirect.toRecord({
type: "customrecord_inspection",
id: inspectionId
});
};
return {
// beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit,
afterSubmit: afterSubmit
};
} );
D17339
01/28/2020, 2:55 PMD17339
01/28/2020, 2:56 PMaaron_tekton
01/28/2020, 2:57 PMaaron_tekton
01/28/2020, 2:57 PMaaron_tekton
01/28/2020, 2:58 PMbattk
01/28/2020, 2:58 PMaaron_tekton
01/28/2020, 2:59 PMcustomrecord_inspection
aaron_tekton
01/28/2020, 2:59 PMbattk
01/28/2020, 2:59 PMaaron_tekton
01/28/2020, 2:59 PMaaron_tekton
01/28/2020, 2:59 PMbattk
01/28/2020, 3:00 PMaaron_tekton
01/28/2020, 3:01 PMaaron_tekton
01/28/2020, 3:02 PMaaron_tekton
01/28/2020, 3:02 PMdmashburn3
01/28/2020, 3:02 PMdmashburn3
01/28/2020, 3:03 PMbattk
01/28/2020, 3:03 PMbattk
01/28/2020, 3:03 PMaaron_tekton
01/28/2020, 3:03 PMaaron_tekton
01/28/2020, 3:04 PMaaron_tekton
01/28/2020, 3:04 PMbattk
01/28/2020, 3:04 PMbattk
01/28/2020, 3:05 PM