- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 12:43 AM
I have PFA, below fields, I have achieved this scenario through Ajax.
u_planned_outage_start
u_planned_outage_end
u_outage_duration
Now I need to achieve
- if old value to new value (u_planned_outage_start) then u_outage_duration field should be clear
- if old value to new value (u_planned_outage_end) then u_outage_duration field should be clear
- if any one field u_planned_outage_start or u_planned_outage_end empty then u_outage_duration field should be clear
This must be client validation ,
Tried onchange but no luck, any help?????
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var Outageduration = g_form.getValue('u_outage_duration');
if(oldValue == newValue){
g_form.clearValue('u_outage_duration',' ');
}
}
I need to add few more condition in this, if there is no value in u_planned_outage_start/u_planned_outage_end then u_outage_duration filed should get clear ...
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var plOutstrt = g_form.getValue('u_planned_outage_start');
var plOutend = g_form.getValue('u_planned_outage_end');
var ajax =new GlideAjax('TSE_Outage_Duration_Calculation');
ajax.addParam('sysparm_name','durCalc');
ajax.addParam('sysparm_strt',plOutstrt);
ajax.addParam('sysparm_end',plOutend);
ajax.getXMLWait();
var answer = ajax.getAnswer();
//alert('answer ' +answer);
g_form.setValue('u_outage_duration', answer);
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 02:37 AM
Hi Santosh,
If the given solution has worked, kindly mark my comment as a correct answer so that the question is removed from the unanswered list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:45 AM
HI,
You will need two OnChange script one onload script to check if anyone field is blank or not. One on Start and one on End.
Example:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
//Type appropriate comment here, and begin script below
var Outageduration = g_form.getValue('u_outage_duration');
if(oldValue == newValue){
g_form.clearValue('u_outage_duration'); You used in wrong way.
}
}
Write Onload script to see if the Start and end date is blank or not. If yes then clearOutage.
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 02:01 AM
Create 2 onchange client scripts on u_planned_outage_start and u_planned_outage_end.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue ===""){
g_form.clearValue('u_outage_duration');
}
//Type appropriate comment here, and begin script below
if(oldValue == newValue){
g_form.clearValue('u_outage_duration');
}
}
For 3rd field, create a onload client script (if yu want to clear on load) or else write the same script on submit (if you want to clear it during submit)
function onLoad() {
//Type appropriate comment here, and begin script below
var outage_start = g_form.getValue("u_planned_outage_start");
var outage_end = g_form.getValue("u_planned_outage_end");
if(outage_start==="" ||outage_end===""){
g_form.clearValue('u_outage_duration');
}
}
Kindly mark the answer as correct or helpful if it helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 02:37 AM
Hi Santosh,
If the given solution has worked, kindly mark my comment as a correct answer so that the question is removed from the unanswered list.