- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 01:59 AM
Hi there. I've created a simple confirm message via an onChange client script:
Type: onChange
Field name: Business Area
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(!g_form.isNewRecord()){
confirm("Changing the Business Area and Assignment group may mean you can no longer access this record due to security rules");
g_form.setValue('assignment_group','');
}
}
However, when the user clicks Cancel, the actions continue, namely, the field changes to the new value they've selected and the assignment_group field clears (as per the line in the script). This is not what I'd expect. I would expect the field to return to its original value and for the script to stop and not clear assignment_group. Can any help me achieve the desired result?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 08:01 AM
Please modify the signature i.e. add one more condition oldValue == newValue
as shown below.....
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || (oldValue === newValue)) {
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 03:33 AM
1st do an alert(oldValue); may be the oldvalue is empty, if alert is showing some valid data, then try this.........
var ans = confirm("Changing the Business Area and Assignment group may mean you can no longer access this record due to security rules");
if (ans == true)
g_form.setValue('assignment_group','');
if (ans == false)
g_form.setValue('category',oldValue);
if (ans == true)
return true;
if (ans == false)
return false;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 06:37 AM
Hey, thanks for this. It does appear to work, however, if you press 'Cancel' on the confirmation prompt, you enter a loop that can only be broken if you press OK. This appears to be because the CS changes the field back to the old value, prompting the confirmation box again, and so on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 08:01 AM
Please modify the signature i.e. add one more condition oldValue == newValue
as shown below.....
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || (oldValue === newValue)) {
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 08:14 AM
Thanks buddy, that's now working perfectly. I appreciate your time on this, really.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 02:40 AM
if(!g_form.isNewRecord()){
if( confirm("Changing the Business Area and Assignment group may mean you can no longer access this record due to security rules")==true)
g_form.setValue('assignment_group','');
return true;
}
else
{
return false;
}
}
Harish