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

amaradiswamy
Kilo Sage

Hi @Vijay kumar S 

 

Have you written onLoad client script with above script? I assume that "url" is field and not a variable on the catalog form. Can you please confirm?

 

If it is a field on the table, try below:

 

Create a UI policy on sc_task table with conditions as State is closed complete or state is closed incomplete or state is closed skipped

 and under UI policy action , select URL field -- visible as true

 

if it is a variable on catalog form, try below:

 

Create onload client script with the script, you already have. Just double check the field name as custom fields will have name starting with "u_"

Hi @amaradiswamy 

 

Thank you for your replay,

yes its a field not variable and field value is correct and I have used alert and got URL.

UI policy also tried but no help on URL other field its making read only not URL

 

oh...got it, I think its not possible to make the text not-clickable with straight forward methods. We might need to use DOM manipulation but it is not a best practice. Let me know if you still want to go with DOM manipulation

Hi @amaradiswamy ,

 

Can you let me know DOM method, so i can give a try.

 

Thank you,

Vijay