Reverting field value to previous value in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 03:22 AM
Hi,
I have a client script, see below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || oldValue == 1 || oldValue == 2) {
return;
}
// if incident already poposed MI then do not run script
if(g_form.getValue('major_incident_state') == 'proposed'){
return false;
}
else {
// Trigger script
}
var priority = g_form.getValue('priority');
if (priority == 1 || priority == 2) {
// This prevents the form from checking if any mandatory fields need filling if the form values change
g_form.checkMandatory = false;
// This prompts the alert box
var response = confirm('Priority 1 & 2 tickets follow the major incident process. Please confirm that you would like to propose this ticket as a Major Incident.');
// If cancel is pressed or the dialog is closed the response is empty
if (response == true){
gsftSubmit(null, g_form.getFormElement(), 'sysverb_mim_propose'); //MUST call the 'Action name' set in this UI Action
} else {
g_form.setValue('impact', oldValue);
g_form.setValue('urgency', oldValue);
g_form.setValue('priority', oldValue);
return false;
}
}
}
If you look at the last else bracket, I want the fields to revert back to their old value, but using oldvalue function reverts all the fields back to the priority field where the onchange client script is pointing to.
1. So i want impact and urgency to revert back to their previous value.
2. If it is a new incident and there is no previous value for all three fields, I want the fields to be set to value 4.
How can I achieve the above please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 03:50 AM
HI,
The first part of your script can be achieved by storing impact and urgency beforehand only in variables and the use that variable to set the value.
eg:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || oldValue == 1 || oldValue == 2) {
return;
}
var impact_old = g_form.getValue('impact');
var urgency_old = g_form.getValue('urgency');
// if incident already poposed MI then do not run script
if(g_form.getValue('short_description') == 'proposed'){
return false;
}
else {
// Trigger script
}
var priority = g_form.getValue('priority');
if (priority == 1 || priority == 2) {
// This prevents the form from checking if any mandatory fields need filling if the form values change
//g_form.checkMandatory = false;
// This prompts the alert box
var response = confirm('Priority 1 & 2 tickets follow the major incident process. Please confirm that you would like to propose this ticket as a Major Incident.');
// If cancel is pressed or the dialog is closed the response is empty
if (response == true){
gsftSubmit(null, g_form.getFormElement(), 'sysverb_mim_propose'); //MUST call the 'Action name' set in this UI Action
} else {
g_form.setValue('impact', impact_old);
g_form.setValue('urgency', urgency_old);
g_form.setValue('priority', oldValue);
return false;
}
}
}
For 2nd part you can add below code in your current code.
if((impact_old == '') && (urgency_old == '')){
impact_old = 4;
urgency_old = 4;
}
or
You can check g_form.isNewRecord() or !g_form.isNewRecord() based on that you can write respective codes.
Regards,
Manisha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 04:17 AM
Thanks
I have added the code like below but doesn't work as expected, can you help me sort the code please?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || oldValue == 1 || oldValue == 2) {
return;
}
// gets value of impact and urgency and stores it as old
var impact_old = g_form.getValue('impact');
var urgency_old = g_form.getValue('urgency');
// if incident already poposed MI then do not run script
if(g_form.getValue('major_incident_state') == 'proposed'){
return false;
}
else {
// Trigger script
}
var priority = g_form.getValue('priority');
if (priority == 1 || priority == 2) {
// This prevents the form from checking if any mandatory fields need filling if the form values change
g_form.checkMandatory = false;
// This prompts the alert box
var response = confirm('Priority 1 & 2 tickets follow the major incident process. Please confirm that you would like to propose this ticket as a Major Incident.');
// If cancel is pressed or the dialog is closed the response is empty
if (response == true){
gsftSubmit(null, g_form.getFormElement(), 'sysverb_mim_propose'); //MUST call the 'Action name' set in this UI Action
} else {
if (g_form.isNewRecord()) {
impact_old = 4;
urgency_old = 4;
priority = 4;
} else {
g_form.setValue('impact', impact_old);
g_form.setValue('urgency', urgency_old);
g_form.setValue('priority', oldValue);
return false;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 04:36 AM
HI ,
Which part is not working, new record part or entirely.
TRy below code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || oldValue == 1 || oldValue == 2) {
return;
}
var impact_old = g_form.getValue('impact');
var urgency_old = g_form.getValue('urgency');
if (g_form.isNewRecord()) {
impact_old = 4;
urgency_old = 4;
priority = 4;
}
// if incident already poposed MI then do not run script
if(g_form.getValue('short_description') == 'proposed'){
return false;
}
else {
// Trigger script
}
var priority = g_form.getValue('priority');
if (priority == 1 || priority == 2) {
// This prevents the form from checking if any mandatory fields need filling if the form values change
//g_form.checkMandatory = false;
// This prompts the alert box
var response = confirm('Priority 1 & 2 tickets follow the major incident process. Please confirm that you would like to propose this ticket as a Major Incident.');
// If cancel is pressed or the dialog is closed the response is empty
if (response == true){
gsftSubmit(null, g_form.getFormElement(), 'sysverb_mim_propose'); //MUST call the 'Action name' set in this UI Action
} else {
g_form.setValue('impact', impact_old);
g_form.setValue('urgency', urgency_old);
g_form.setValue('priority', oldValue);
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 04:40 AM
I believe your last else is just for Priority 1 and 2, if user clicks cancel in confirmation box..
What is the use case of Priority 3 and 4.