how to make reference field read only which contain URL ?

Vijay kumar S
Tera Contributor

Hi All, 

 

I need to make field read-only which contain URL after completing task .

 

I have tried UI policy and onLoad client script 

  var state=g_form.getValue('state');
   alert("in script"+state);
   if(state==3||state==4||state==7)
   {
       alert("in if loop script"); // got alert 
    g_form.setReadOnly('url',true);
   }
 
but not working ,
 
Can any once help me on this 
1 ACCEPTED SOLUTION

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.


Screenshot (181).png

 

Screenshot (182).png

 

Screenshot (183).png

 

Screenshot (184).png

   

 

View solution in original post

8 REPLIES 8

Siddhesh Jadhav
Kilo Sage

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

Screenshot (177).png

 

Screenshot (178).png

  

Screenshot (179).png

Screenshot (180).png

 

Hi @Siddhesh Jadhav ,

 

I have tried above method its working with fields but not with URL.

please find below attachment.

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   setTimeout(function () {
var state = g_form.getValue('state');
alert("State: " + state);

if (state == '3' || state == '4' || state == '7'|| state == '6') {
alert("Setting caller field as read-only");
g_form.setReadOnly('u_url', true);
}
}, 500); // Delay for 500 milliseconds to ensure the form is fully loaded

}
 
Thank you,
Vijay

 

Hi @Vijay kumar S 

 

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 :

AmitVerma_0-1727674781523.png

 

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);
    }
}

 

AmitVerma_1-1727675075048.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

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.


Screenshot (181).png

 

Screenshot (182).png

 

Screenshot (183).png

 

Screenshot (184).png