- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 02:28 AM
Hi All,
I need to make field read-only which contain URL after completing task .
I have tried UI policy and onLoad client script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2024 11:31 PM
Hi @Vijay kumar S ,
To disable the URL field effectively, we need to perform some DOM manipulation within the onLoad client script. Additionally, please ensure that the "Isolate script" checkbox is set to false when you're editing the client script. This allows us to access the current object model and manipulate the DOM elements as needed.
You can find the ID of the anchor tag by inspecting it using the developer tools (press F12 in your browser, then navigate to the Elements tab and look for the <a> tag).
Here’s an updated version of the script that you can use:
function onLoad() {
setTimeout(function () {
var state = g_form.getValue('state');
if (state == '3' || state == '4' || state == '7' || state == '6') {
g_form.setReadOnly('u_url', true);
var urlAnchor = document.getElementById('incident.u_url_link');
if (urlAnchor) {
urlAnchor.style.pointerEvents = 'none'; // Prevents clicks on the link
urlAnchor.style.cursor = 'default'; // Change the cursor to default
urlAnchor.style.textDecoration = 'none'; // Remove underline
urlAnchor.style.color = 'gray'; // Optionally gray out the link
}
}
}, 1500); // Wait 1.5 seconds to ensure the form and elements are fully loaded
}
Key Points
1. Isolate Script Checkbox: Ensure that the "Isolate script" checkbox is set to false to allow access to the current object model and manipulate elements correctly.
Best regards,
Siddhesh Jadhav
I hope this helps! If this resolves your issue, kindly mark my answer as helpful and accepted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 09:38 PM
Hi @Vijay kumar S,
The issue seems to be related to the timing of the script execution. The form might not be fully loaded when the script runs. To resolve this, you can add a slight delay using setTimeout() to ensure that the form is completely loaded before applying the read-only setting.
I have used the "caller_id" field in this example as it’s a reference field, but you can change it to the field of your choice as per your requirements.
Here’s a modified version of the onLoad Client Script that works:
function onLoad() {
setTimeout(function () {
var state = g_form.getValue('state');
alert("State: " + state);
if (state == '3' || state == '4' || state == '7') {
alert("Setting caller field as read-only");
g_form.setReadOnly('caller_id', true);
}
}, 500); // Delay for 500 milliseconds to ensure the form is fully loaded
}
Key Points:
1. setTimeout(): The delay ensures the form is fully loaded before making the field read-only. Without this delay, the script might be trying to set the field before the form is ready.
---
I hope this helps! If this resolves your issue, kindly mark my answer as helpful and accepted.
Thanks,
Siddhesh Jadhav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2024 10:11 PM
Hi @Siddhesh Jadhav ,
I have tried above method its working with fields but not with URL.
please find below attachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2024 10:44 PM
From a URL field perspective, when the URL field is not read-only, you get the option to edit the URL value by clicking on the unlock icon as shown below :
If the field is marked as read-only, you will not get the unlock icon and thus, you will not be able to edit variable value so technically, a URL field is marked Read-only if you are not getting the unlock icon. You will not see the field being grayed out like other fields. Refer below screenshot where the unlock icon is not available once I made use of the below On-Load Client script on Incident form :
function onLoad() {
//Type appropriate comment here, and begin script below
var state = g_form.getValue('state');
if (state == '3' || state == '4' || state == '7' || state == '6') {
alert(state);
g_form.setReadOnly('u_url1', true);
}
}
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2024 11:31 PM
Hi @Vijay kumar S ,
To disable the URL field effectively, we need to perform some DOM manipulation within the onLoad client script. Additionally, please ensure that the "Isolate script" checkbox is set to false when you're editing the client script. This allows us to access the current object model and manipulate the DOM elements as needed.
You can find the ID of the anchor tag by inspecting it using the developer tools (press F12 in your browser, then navigate to the Elements tab and look for the <a> tag).
Here’s an updated version of the script that you can use:
function onLoad() {
setTimeout(function () {
var state = g_form.getValue('state');
if (state == '3' || state == '4' || state == '7' || state == '6') {
g_form.setReadOnly('u_url', true);
var urlAnchor = document.getElementById('incident.u_url_link');
if (urlAnchor) {
urlAnchor.style.pointerEvents = 'none'; // Prevents clicks on the link
urlAnchor.style.cursor = 'default'; // Change the cursor to default
urlAnchor.style.textDecoration = 'none'; // Remove underline
urlAnchor.style.color = 'gray'; // Optionally gray out the link
}
}
}, 1500); // Wait 1.5 seconds to ensure the form and elements are fully loaded
}
Key Points
1. Isolate Script Checkbox: Ensure that the "Isolate script" checkbox is set to false to allow access to the current object model and manipulate elements correctly.
Best regards,
Siddhesh Jadhav
I hope this helps! If this resolves your issue, kindly mark my answer as helpful and accepted.