- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2020 09:54 PM
Hi ,
I wanted to make a field 'due_date mandatory an read only in new state. So i written client script as needed but the field is only getting mandatory not read only in new state but went we open an existing problem field becomes both mandatory and read only. There are more conditions also for the field to be readonly it is there in the code. But the problem prevails in the New state.
Attaching the code written in client script.
Thanks in Advance.
Thanks,
Glenn
function onLoad() {
// Type appropriate comment here, and begin script below
var cdt = g_form.getValue('opened_at'); //First Date/Time field
var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeBeforeNow');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer < 14){
if(!g_user.hasRole('problem_manager')){
g_form.setReadOnly('due_date',true);
}
}
g_form.setMandatory('due_date',true);
}
}
Solved! Go to Solution.
- Labels:
-
Multiple Versions
-
Problem Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 04:16 AM
Sorry
Actually was away for day,
the issue was that value wasn't populated so both mandatory and readonly wont work together.
So the solution i did was instead of making it mandatory gave Bussiness rules tovalidate and populate error message as to the field should be mandatory.
Thanks,
Glenn

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2020 10:21 PM
Hi there,
The due_date field, is that in all cases filled? If it's not filled, and you are making it mandatory, then it will not get read-only.
I would think, that if the answer < 14 and you don't have the problem_manager role, the field should always be read-only? So why then also setting mandatory?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2020 10:22 PM
Hi,
Try this logic,
// if state is new (assume 1 is back end value for new state) and due_date field is empty ie. null.
if(state == '1'){
if(due_date == ''){
g_form.setMandatory('due_date','true');
}
else{
g_form.setMandatory('due_date','true');
g_form.setReadOnly('due_date','true');
}
}
Hope this will clear your doubts,
Regards,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2020 09:41 AM
Hi there,
Did this solve your question? Or do we need to follow-up on this?
Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2020 11:52 AM
Hi there,
Did this solve your question? Or do we need to follow-up on this?
Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field