- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 11:00 PM
Hi,
Please find below scenario:
On Incident form,
if state field old value is New|1 and I change it to inProgress|2, then it should popup an alert as old value : New|1 and new value: inProgess|2.
Now, if I change state field New|1 again then it should be alerted like oldValue: inProgress|2 and newValue : New|1
Note: Form should not be saved. It should be achieved by without saving form.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 11:05 PM
For above use case please find below solution :
We need to write on load client script on incident table :
function onLoad() {
//Type appropriate comment here, and begin script below
var oldStateValue = g_form.getValue('state');
function showAlert() {
var newStateValue = g_form.getValue('state');
alert('Old State: ' + oldStateValue + '\nNew State: ' + newStateValue);
oldStateValue = newStateValue;
}
g_form.getControl('state').addEventListener('change', showAlert);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 11:20 PM
Hi @NishantDhole ,
For above use case please find below solution :
We need to write on load client script on incident table :
function onLoad() {
//Type appropriate comment here, and begin script below
var oldStateValue = g_form.getValue('state');
function showAlert() {
var newStateValue = g_form.getValue('state');
alert('Old State: ' + oldStateValue + '\nNew State: ' + newStateValue);
oldStateValue = newStateValue;
}
g_form.getControl('state').addEventListener('change', showAlert);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 11:04 PM
@NishantDhole if that is the case then yeah you can go with the below code:
function onLoad() {
// Capture the initial value of the state field
var oldStateValue = g_form.getValue('state');
// Define the function to display the alert with old and new state values
function showAlert() {
var newStateValue = g_form.getValue('state');
alert('Old State: ' + oldStateValue + '\nNew State: ' + newStateValue);
oldStateValue = newStateValue; // Update the old state value to the current state
}
// Add an event listener to the state field to detect changes
g_form.getControl('state').addEventListener('change', showAlert);
}
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 08:59 AM
Hi @NishantDhole for your scenario i would prefer using OnChange client script as it would give you alert immediatly once you change the state.
try using below code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === oldValue) {
return;
}
var oldLabel = g_form.getOption('state', oldValue).text;
var newLabel = g_form.getOption('state', newValue).text;
alert('Old Value: ' + oldLabel + '\nNew Value: ' + newLabel);
}
@Rohit99 your code looks good but it would give you backend name of the choice.
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 10:59 PM
Hi @Satishkumar B ,
If I want old value only once then i would have used it. but my requirement was different. I am change both value multiple times so old value and new value also changing simultaneously. And as per your solution old value remain same. if i change state field value multiple time then old value also should change.
Consider scenario:
case 1)The state field has the value inProgress, now if change the state field value to on hold
in above case 1 : alert should populate like old value: inprogress or 2 and new Value : onhold or 3.
case2) now on same incident if change the state field value to new without loading and saving the form then
alert should populate like : old value : onhold or 3 and new value : new or 1
In your case it will always show same old value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 11:04 PM
@NishantDhole if that is the case then yeah you can go with the below code:
function onLoad() {
// Capture the initial value of the state field
var oldStateValue = g_form.getValue('state');
// Define the function to display the alert with old and new state values
function showAlert() {
var newStateValue = g_form.getValue('state');
alert('Old State: ' + oldStateValue + '\nNew State: ' + newStateValue);
oldStateValue = newStateValue; // Update the old state value to the current state
}
// Add an event listener to the state field to detect changes
g_form.getControl('state').addEventListener('change', showAlert);
}
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 11:16 PM