
- 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-09-2017 03:22 PM
Please check below thread which has solution to make field read only in SP
How to set readonly variables on Service Portal?
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 05:58 AM
Hello Sachin,
Thanks for your help.
If I understood correctly the script, it will make the date variable RO. I can do that with a UI Policy without editing the widget.
What I need is to make RO only the text box of the date variable and still have available the calendar to select the date. In this way, the user is forced to use the calendar to select the date and not writing it in the text box.
I hope now is more clear what I need to accomplish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 06:28 AM
I don't think what you're trying to do is possible. I'd either:
- create an OnChange Client Script to check if the format of the field was correct after it was updated, and send an alert while also wiping the field clear OR
- create separate fields to fill in smaller chunks of the date/timefield, then populate the actual field in an OnSubmit Client Script (this sounds much more painful to do btw)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 01:14 PM
Hi jued0001,
Thanks for your suggestion.
I'm already going by the date format validation way.
Hope in next releases would be possible to implement.
Have a good weekend!