getControl is not working in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 08:47 AM
Hi All,
I have a field called -"Start Date" of type 'Date' on the catalog item. The requirement was to make the field read only so that the user can make use of Calendar and do not enter the date manually. So, I have written a onLoad catalog client script to make it readOnly.
g_form.getControl('start_date').readOnly=true;
This script works for the Desktop view but doesn't work in the service portal. Can anyone suggest some logic which can work on both UI Type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 05:06 AM
not all functions for getControl() work in portal.
you can use DOM manipulation
This worked for me in both native and portal
function onLoad() {
//Type appropriate comment here, and begin script below
setTimeout(function() {
try {
var variableName = 'start_date';
if (window == null) {
// portal
this.document.getElementById('sp_formfield_' + variableName).setAttribute('readOnly', true);
}
} catch (ex) {
// native
var variableName = 'start_date';
g_form.getControl(variableName).readOnly = true;
}
}, 2000);
}
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 03:36 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 04:17 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader