Field should be in red color when it is checked.

Anjaneyulu1
Giga Contributor

Hii All,

 

Create below fields in Incident form –
1. ‘Critical Incident’ – Type True/False
2. ‘Marked as Critical by’ – Type String
3. ‘Marked Critical at’ – Type Date
Scenario :
1. When ‘Critical Incident’ is checked as TRUE, both fields 2 & 3 should be visible in form else they should be hidden.  2.‘Marked as Critical by’ should be auto – populated by the name of person who has marked ‘Critical Incident’ as TRUE and current date in ‘Marked Critical at’.
3. When ‘Critical Incident’ is checked as TRUE, the field should appear RED in colour.

-->i have created above 3 fields and i have done 1st point through ui policy for hidden and visible.

-->please help me on 2nd and 3rd point.

 

Regards,

Anjaneyulu

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can refer this script to set color to field

use it as per your requirement

var control = g_form.getControl('u_marked_as_critical_by');

	if(g_form.getValue('u_marked_as_critical_by').toString() == 'true'){
		control.style.color = 'red'; // to set the color of field
	}
	else{
		control.style.color = ''; // clear it
	}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi

although you did not specify in which experience (UI16, Service Portal, Workspace) you want to have that feature, it is not possible with OOTB means. The only alternative would be manipulating the DOM but this is not recommended.

Kind regards
Maik

Hii Maik,

it is on incident form all fields UI16

i have written onchange CS for 2nd point but date is not populating currently

var usr = g_user.getFullName();
var date = new Date();

if (newValue == 'true') {

g_form.setValue('u_marked_as_critical_by', usr);
g_form.setValue('u_marked_critical_at', date);

}

could you please help me on current date should be populated on 'u_marked_critical_at'.

Hi

only providing a part of a Client Script is not helpful.

Please provide the complete Script as well as a screenshot from the configuration of the Client Script.

Kind regards
Maik

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can refer this script to set color to field

use it as per your requirement

var control = g_form.getControl('u_marked_as_critical_by');

	if(g_form.getValue('u_marked_as_critical_by').toString() == 'true'){
		control.style.color = 'red'; // to set the color of field
	}
	else{
		control.style.color = ''; // clear it
	}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader