Make Field readonly according to the condition

rah dev
Tera Contributor

Hi Community, Good Day!!!!
As we know that in incident table when we add value on Caller field then for some users, 'location' field's value auto-populates. So, in my requirement, if location field gets auto-populates, make it read-only, like in below:

Kumar887_0-1694011413703.png

 

and when 'location' does not gets auto-populates and user sets it manually, then make it editable even it is set.

Thanks in Advance!!

1 REPLY 1

Vrushali  Kolte
Mega Sage

Hi @rah dev ,

Based on your description, you can achieve the desired behavior by creating a client script in the catalog item. This client script will run when there's a change in the 'Caller' field. Attached is the snapshot for same. Here's an example of the code you can use:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    var loc = g_form.getValue('location'); //get the value of location field
    if (loc != '') {  // if it has value, then only make it readonly
        g_form.setReadOnly('location', true);
    }
}

 

 If my answer solves your issue, please mark it as Helpful 👍 and accepted ✔️ based on the impact.