Ingorca
05/05/2022, 5:04 PMbattk
05/05/2022, 5:20 PMbattk
05/05/2022, 5:20 PMbattk
05/05/2022, 5:21 PMIngorca
05/05/2022, 7:33 PMIngorca
05/05/2022, 7:34 PMbattk
05/05/2022, 7:48 PMbattk
05/05/2022, 7:49 PMIngorca
05/05/2022, 8:04 PMbattk
05/05/2022, 8:04 PMIngorca
05/05/2022, 8:54 PMbattk
05/05/2022, 8:55 PMbattk
05/05/2022, 8:55 PMIngorca
05/05/2022, 9:07 PMIngorca
05/05/2022, 9:08 PMbattk
05/05/2022, 9:08 PMbattk
05/05/2022, 9:08 PMIngorca
05/05/2022, 9:10 PMbattk
05/05/2022, 9:11 PMIngorca
05/05/2022, 9:11 PMbattk
05/05/2022, 9:13 PMbattk
05/05/2022, 9:13 PMIngorca
05/05/2022, 9:14 PMSuiteScript 2.x
var timeRecord = record.load({
id: 1,
type: 'customrecord_currenttime'
});
var timezone = config.load({type: config.Type.USER_PREFERENCES}).getValue({fieldId: "TIMEZONE"})
var currentTime = timeRecord.getValue('custrecord_currenttime_now');
var usersTime = format.format({
value: usersTime,
type: format.Type.DATETIME,
timezone: format.Timezone.timezone
});
Like this?Ingorca
05/05/2022, 9:14 PMIngorca
05/05/2022, 9:15 PMbattk
05/05/2022, 9:16 PMbattk
05/05/2022, 9:17 PMbattk
05/05/2022, 9:17 PMbattk
05/05/2022, 9:17 PMbattk
05/05/2022, 9:17 PMIngorca
05/05/2022, 9:25 PMbattk
05/05/2022, 9:26 PMbattk
05/05/2022, 9:26 PMIngorca
05/05/2022, 9:31 PMbattk
05/05/2022, 9:32 PMbattk
05/05/2022, 9:32 PMIngorca
05/05/2022, 9:32 PMbattk
05/05/2022, 9:35 PMIngorca
05/05/2022, 9:39 PMbattk
05/05/2022, 9:40 PMbattk
05/05/2022, 9:41 PMbattk
05/05/2022, 9:41 PMIngorca
05/05/2022, 9:44 PMIngorca
05/05/2022, 9:52 PMbattk
05/05/2022, 9:59 PMbattk
05/05/2022, 10:00 PMbattk
05/05/2022, 10:01 PMbattk
05/05/2022, 10:03 PMIngorca
05/05/2022, 10:04 PMIngorca
05/06/2022, 10:11 AMHello, here is the script I've definetly done:
Ingorca
05/06/2022, 10:11 AMfunction validateField(scriptContext) {
var curRec = scriptContext.currentRecord;
var fieldName = scriptContext.fieldId;
var today = new Date();
if (fieldName === 'custrecord_date_souhaitee') {
var recDate = curRec.getValue(fieldName);
if (recDate < today){
alert('Vous ne pouvez pas entrer une date antérieure à la date du jour');
curRec.setValue({
fieldId: 'custrecord_date_souhaitee',
value: null
});
}
}
if (fieldName === 'custrecord_heure_souhaitee') {
var recTime = curRec.getValue(fieldName);
var curTime = today.getTime();
if ((recTime < curTime) & (recDate = today)){
alert('Votre date de planification étant ce jour, vous devez entrer une heure supérieure à l\'heure actuelle');
curRec.setValue({
fieldId: 'custrecord_heure_souhaitee',
value: null
});
}
}
}
Ingorca
05/06/2022, 10:14 AMError: JS_EXCEPTION
RangeError Maximum call stack size exceeded
Ingorca
05/06/2022, 10:14 AMIngorca
05/06/2022, 10:14 AMIngorca
05/06/2022, 10:14 AMbattk
05/06/2022, 10:15 AMbattk
05/06/2022, 10:15 AMbattk
05/06/2022, 10:16 AMbattk
05/06/2022, 10:16 AMIngorca
05/06/2022, 10:17 AMbattk
05/06/2022, 10:21 AMbattk
05/06/2022, 10:22 AMIngorca
05/06/2022, 10:34 AMIngorca
05/06/2022, 10:35 AM/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/ui/dialog'],
function(record, dialog) {
function fieldChanged(scriptContext) {
var currentRecord = scriptContext.currentRecord;
var fieldName = scriptContext.fieldId;
if(fieldName === 'custrecord_type_d_intervention'){
var type_intervention = currentRecord.getValue({fieldId:fieldName});
if(type_intervention == 'Maintenance'){
alert('Veuillez renseigner le problème faisant office à cette maintenance');
var problemField = currentRecord.getField({
id: 'custrecord_probleme'
});
problemField.updateDisplayType({
displayType: 'NORMAL'
});
}
}
}
function validateField(scriptContext) {
var curRec = scriptContext.currentRecord;
var fieldName = scriptContext.fieldId;
var today = new Date();
if (fieldName === 'custrecord_date_souhaitee') {
var recDate = curRec.getValue(fieldName);
if (recDate < today){
alert('Vous ne pouvez pas entrer une date antérieure à la date du jour');
curRec.setValue({
fieldId: 'custrecord_date_souhaitee',
value: null,
ignoreFieldChange: true,
forceSyncSourcing: true
});
}
}
if (fieldName === 'custrecord_heure_souhaitee') {
var recTime = curRec.getValue(fieldName);
var curTime = today.getTime();
if ((recTime < curTime) & (recDate = today)){
alert('Votre date de planification étant ce jour, vous devez entrer une heure supérieure à l\'heure actuelle');
curRec.setValue({
fieldId: 'custrecord_heure_souhaitee',
value: null,
ignoreFieldChange: true,
forceSyncSourcing: true
});
}
}
return true;
}
return {
fieldChanged: fieldChanged,
validateField: validateField,
};
});
Ingorca
05/06/2022, 10:35 AMbattk
05/06/2022, 10:40 AMcustrecord_date_souhaitee
should still workbattk
05/06/2022, 10:40 AMbattk
05/06/2022, 10:40 AMif ((recTime < curTime) & (recDate = today)){
is basically wrong in multiple placesIngorca
05/06/2022, 10:41 AMbattk
05/06/2022, 10:41 AMbattk
05/06/2022, 10:42 AMbattk
05/06/2022, 10:42 AMbattk
05/06/2022, 10:44 AMMaintenance
battk
05/06/2022, 10:46 AMIngorca
05/06/2022, 10:46 AMbattk
05/06/2022, 10:47 AMbattk
05/06/2022, 10:47 AMIngorca
05/06/2022, 10:49 AMbattk
05/06/2022, 10:52 AMIngorca
05/06/2022, 11:05 AMIngorca
05/06/2022, 11:06 AMbattk
05/06/2022, 11:13 AMbattk
05/06/2022, 11:14 AMIngorca
05/06/2022, 11:38 AMfunction fieldChanged(scriptContext) {
var currentRecord = scriptContext.currentRecord;
var fieldName = scriptContext.fieldId;
if(fieldName === 'custrecord_type_d_intervention'){
var type_intervention = JSON.stringify(currentRecord.getSelectOptions({
filter : 'Maintenance',
operator : 'is'
}));
if(type_intervention === 'Maintenance'){
alert('Veuillez renseigner le problème faisant office à cette maintenance');
var problemField = currentRecord.getField({
id: 'custrecord_probleme'
});
problemField.isDisplay = true;
}
}
}
Ingorca
05/06/2022, 11:39 AMbattk
05/06/2022, 11:41 AMbattk
05/06/2022, 11:42 AMIngorca
05/06/2022, 11:48 AMbattk
05/06/2022, 11:48 AMbattk
05/06/2022, 11:49 AMvar type_intervention = currentRecord.getValue({fieldId:fieldName});
battk
05/06/2022, 11:49 AMbattk
05/06/2022, 11:49 AMbattk
05/06/2022, 11:50 AM