- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 12:08 AM
Hi all,
I have a choice field which has four values 'Low,medium,high,critical', as per the value selected I have to display background colour in that field.I have Configured styles accordingly but still it doesnt show the background colour.
Can anyone just help me figure out what might be the issue?
Solved! Go to Solution.
- Labels:
-
Policy and Compliance Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2020 01:09 AM
Hi
I am back with some information for you.The problem you are facing in the client script is because you have marked the field read only via dictionary entry.
Am I right?
I analysed it deeply & found
Other scenario where this approach fails when you have data policies defined for a field like in incident we have data policies on the priorty field.
I tried it.
If the field is custom field, you can proceed as:
Now what you can do:
- First of all if you want to achieve it don't mark it readonly via sys_dictionary entry.It is not possible if it has been marked as readonly via dictionary entry.
- Take this approach:
function onLoad() {
var rating=g_form.getValue("u_inherent_risk_score_rating");
if(rating == "1"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="green";
g_form.setReadOnly('impact',true);
}
if(rating == "2"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="light green";
g_form.setReadOnly('impact',true);
}
if(rating == "3"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="yellow";
g_form.setReadOnly('impact',true);
}
if(rating == "4"){
g_form.getControl("u_inherent_risk_score_rating").style.backgroundColor="red";
g_form.setReadOnly('impact',true);
}
}
But you have to create a list edit view to prevemt that field to be edited in the list view.
Mark it helpful/correct.
Thanks
Sudhanshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 12:13 AM
Hi Sanel,
field styles which has value depending on the javascript would be running on list and not on form
is the field name correct 'u_choice_14'?
I believe it should be choice_14 since that might be custom created on Policy Exception table
Can you try checking with quotes for the value '1'
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 12:44 AM
Hi Sanel,
if you require to show the field styles on form then you need to write onload client script and show the field styles accordingly.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 12:19 AM
Hi Sanel,
Check this thread which is similar to your requirement
Please let me know if this helps.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 12:32 AM
Hi Sanel,
Write onChange client script on choice field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var choiceVal= g_form.getValue('u_choice_14');
if(choiceVal=='1'){
var choice1=g_form.getControl('u_choice_14');
choice1.style.backgroundColor='red';
}
else if(choiceVal=='2'){
var choice2=g_form.getControl('u_choice_14');
choice2.style.backgroundColor='green';
}
else if(choiceVal=='3'){
var choice3=g_form.getControl('u_choice_14');
choice3.style.backgroundColor='orange';
}
else{
var choice4=g_form.getControl('u_choice_14');
choice4.style.backgroundColor='blue';
}
}
Thanks,
Dhananjay.
