how to clear the field value

Santosh Kallim1
Giga Contributor

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 

  1. if old value  to new value  (u_planned_outage_start) then u_outage_duration field should be clear
  2. if old value  to new value  (u_planned_outage_end) then u_outage_duration field should be clear
  3. 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
}

 

1 ACCEPTED SOLUTION

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.

View solution in original post

3 REPLIES 3

Ashutosh Munot1
Kilo Patron
Kilo Patron

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

asifnoor
Kilo Patron

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.

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.