Assigned to and State fields readonly

Shiva Kumar2
Kilo Guru

Hi 

 

While creating Incident, I need State and Assigned to fields become read-only, after incident creation those two fields become editable, please help me how to achieve this?

 

Thanks,

Shiva

1 ACCEPTED SOLUTION

Harish Kota
Kilo Sage

Hi @Shiva Kumar2 

 

Please use an onLoad Client Script to achieve your requirement.

function onLoad() {

if(g_form.isNewRecord() ) {

    g_form.setReadOnly("state", true);

    g_form.setReadOnly("assigned_to", true);

}

}

 

Please hit like/accept as solution if it works for you.

 

Thanks,

Harish Kota

View solution in original post

4 REPLIES 4

Harish Kota
Kilo Sage

Hi @Shiva Kumar2 

 

Please use an onLoad Client Script to achieve your requirement.

function onLoad() {

if(g_form.isNewRecord() ) {

    g_form.setReadOnly("state", true);

    g_form.setReadOnly("assigned_to", true);

}

}

 

Please hit like/accept as solution if it works for you.

 

Thanks,

Harish Kota

Thank you Harish for the script, It works me.

Thank you all for your responses, I have accepted Harish solution as he has given first reply.

Ahmmed Ali
Mega Sage

Write a onload client script on incident table with below script:

 

if(g_form.isNewRecord()){
    g_form.setMandatory("assigned_to", false);
    g_form.setReadOnly("assigned_to", true);
    g_form.setMandatory("state", false);
    g_form.setReadOnly("state", true);
}
 
 
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

SinghBalwant
Kilo Guru

There are two ways to do achieve this requirement. Approach shared below:

 

The client script will check if the incident is new and, if it is, it will set the State and Assigned To fields to read-only.

Code snippet

 

function onLoad() {

if(g_form.isNewRecord() ) {

    g_form.setReadOnly("state", true);

    g_form.setReadOnly("assigned_to", true);

}

}

 

ACL

The ACL will restrict users from editing the State and Assigned To fields, except for when the incident is new.

rule incident_state_readonly {

  when {

    // The incident is new.

    incident.getState() == 'New'

  }

  then {

    // Allow users to edit the incident state and assigned to fields.

    allow update incident.state;

    allow update incident.assigned_to;

  }

}

Once you have added the client script/ACL, the State and Assigned To fields will be read-only when you create a new incident. After the incident has been created, the fields will be editable.

 

Please let me know if my feedback was helpful and resolved your issue. If it was, please click the "Helpful" button below.

I appreciate your feedback! It helps me to improve my responses and better serve you in the future.