
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 01:51 PM
Hi all,
I'm kind of new developing in SN.
I need to find a way to make read-only the text box of the date variable so force the end user to use the calendar (datepicker) to select the date in Service Portal.
The image is from the standard UI. The text box is disabled but I'm able to select the date with the calendar (datepicker).
So far, I've been able to make it work in the standard UI with this Catalog Client Script:
UI Type: Both
Type: onLoad
function onLoad() {
// Checks if the form is loaded in mobile or desktop
if (window == null) {
// For Service Portal - Currently not working
//g_form.hasField('date_variable').style.backgroundColor = '#F0F0F0';
//g_form.hasField('date_variable').readOnly = true;
document.observe("dom:loaded", function(){
$('date_variable').setAttribute('disabled', true);
});
} else {
// For standard UI
g_form.getControl('date_variable').style.backgroundColor = '#F0F0F0'; // Sets gray color to background
g_form.getControl('date_variable').readOnly = true; // Sets the text box as RO
}
}
g_form.getControl() does not work in Service Portal.
I've researched all day and still haven't found a way to make it work in SP.
Any help is greatly appreciated.
Thanks!
Solved! Go to Solution.
- Labels:
-
Now Mobile
-
Service Catalog
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2017 05:56 AM
If you only need this on one specific Date variable...
Get the sys_id of the variable
- Service Catalog > Maintain Items > [open item the variable belongs to]
- Variables (related list) > right-click on the variable > Copy sys_id
Create a Catalog UI Policy
- Service Catalog > Maintain Items > [open item the variable belongs to]
- UI Policies (related list) > New
- Onload: true
- Run script: true
- Run scripts in UI type: All
- Execute if true:
function onCondition() {
var $ = this.jQuery;
$('input[id*="yourSysIdHere"]').attr('readonly', true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2017 05:56 AM
If you only need this on one specific Date variable...
Get the sys_id of the variable
- Service Catalog > Maintain Items > [open item the variable belongs to]
- Variables (related list) > right-click on the variable > Copy sys_id
Create a Catalog UI Policy
- Service Catalog > Maintain Items > [open item the variable belongs to]
- UI Policies (related list) > New
- Onload: true
- Run script: true
- Run scripts in UI type: All
- Execute if true:
function onCondition() {
var $ = this.jQuery;
$('input[id*="yourSysIdHere"]').attr('readonly', true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 10:29 AM
Thanks for you recommendation Dan.
I've tested it but unfortunately, it didn't worked in SP. I was still able to type in the date text box.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 11:46 PM
Hi Kyu,
I've tested this in Service Portal and it was working, can you add an alert or some other debug output to the script to ensure that it is executing?
Thanks
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2018 10:11 AM
This works great for the main application, but will not work with the Service Portal. JQuery and Angular is not getting along these days. Also I never could find a UI type field in the Catalog UI Policy form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2019 06:36 AM
We were able to achieve the ready only text box on the date variable in Service Portal by using your suggestion with Kingston:
function onCondition() {
var $ = this.jQuery;
$('input[id*="yourSysIdHere"]').attr('readonly', true);
}
However, it is no longer working for us in London. The text box is no longer grayed out. Any new suggestions for achieving the same effect in the London release?