- 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 01:44 AM
Hi Sanel,
If this has resolved kindly mark this as correct and close the thread so others will use same in future.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 01:48 AM
Thanks Dhananjay , your reply helped , just one problem is I have to keep my field as read only , and when I change it to read only through dictionary the Color is not applied.What can I do here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 01:54 AM
Hi Sanel,
field style should be applied irrespective of field is read-only or editable.
Can you explain what is your requirement here?
applying field styles or setting field as read-only?
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 02:17 AM
Hi
And you saying that it should be applied irrespective of whether it is read only or editable , but in my case its getting applied only if the field is editable .
So I want to know what should I change so that i am able to see the background color even if the field is read only?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2020 02:24 AM
Hi Sanel,
So you are writing some onchange client script on other field and setting the field as read-only or editable at the same time you can set the field styles
please share script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
