Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

On change client script to display alert

RudhraKAM
Tera Guru

Can some one help me with on change client script ,

Requirement is on incident if i select a CI i need to alert the user if the CI's status is test ( we have CI's status where it can be on test , dev or prod ) if they select the CI with status test we need to alert the user 

   
   function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
if (newValue == ''){
       
alert('Are you sure ');
}
}
1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Use blow client script and update as per your CI status field values

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

	var ci = g_form.getReference('cmdb_ci');

	
	if(ci.install_status == '1'){
		
		alert('CI status is TEST');
		
	}
   //Type appropriate comment here, and begin script below
   
}

 

Regards,

Sachin

View solution in original post

3 REPLIES 3

Yash Agrawal1
Tera Guru

helllo kam

Actually if you want to give a user alert msg after select ci if the ci is of test

 

just use this below code

 

function onChange(control, oldValue, newValue, isLoading, isTemplate)

{

   if (isLoading || newValue === '')

   { return; }

   if (newValue =="test")

    {

        alert('You new value is test');

     }

    if (newValue =="prod")

    {

        alert('You new value is prod');

     }

}

 

Please mark this answer as correct/helpful .If your work will be done ny this code...

 

Thankyou 

Yash.k.agrawal

sachin_namjoshi
Kilo Patron
Kilo Patron

Use blow client script and update as per your CI status field values

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

	var ci = g_form.getReference('cmdb_ci');

	
	if(ci.install_status == '1'){
		
		alert('CI status is TEST');
		
	}
   //Type appropriate comment here, and begin script below
   
}

 

Regards,

Sachin

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Try using something as below.

   
   function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

var getci=g_form.getReference('cmdb_ci',getcistatus);//considering cmdb_ci is CI field on form which is a reference field
alert('CI selected is '+getci);


function getcistatus(getci)
{
var cistats=g_form.getValue(getci.status);       
alert('Status for selected CI is '+cistats);

}
}

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.