- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I want to force work notes to be required whenever any update on Change Request when in Scheduled state. I'm using a onChange client script, below is my script is not working:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
HI @athavichith ,
try this onSubmit client script instead of onChange
function onSubmit() {
var state = g_form.getValue('state');
if (!g_form.isNewRecord() && state == '-2' && !g_form.getValue('work_notes')) {
if (Object.keys(g_form.modifiedFields).length) {
g_form.setMandatory('work_notes', true);
g_form.addErrorMessage('Work note is required when in Scheduled state and record is updated');
return false;
}
return true;
}
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
That will run when the field it is defined for is changed, and the logic will execute when the newValue = ''. Seems the problem is with you "if()" statement logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
The way your script is written you are putting all logic inside the conditional for if(isLoading || newValue === ")
update your script with the following formatting:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//insert your scripted logic here
var state = g_form.getValue('state');
if(!g_form.isNewRecord() && state == -2) {
g_form.setMandatory('work_notes', true);
g_form.addErrorMessage('Work note is required when in Scheduled state and record is updated');
}
}
Without more context on where you are applying the onChange script it's hard to troubleshoot but this should work if you are applying it as an onChange script targeting the state field.
I would also recommend adding an else to your if that reverts the setting of work_notes back to not mandatory for handling instances where the user may set the state to scheduled and then change it to another state for some reason.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
HI @athavichith ,
try this onSubmit client script instead of onChange
function onSubmit() {
var state = g_form.getValue('state');
if (!g_form.isNewRecord() && state == '-2' && !g_form.getValue('work_notes')) {
if (Object.keys(g_form.modifiedFields).length) {
g_form.setMandatory('work_notes', true);
g_form.addErrorMessage('Work note is required when in Scheduled state and record is updated');
return false;
}
return true;
}
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
