Make a field read-only on a condition

Riya17
Giga Contributor

I have a 'Release Phase' form and related list at the bottom. When I create a 'Release Task', the state field on release phase should be set to 'Ready' and read-only.  'Release Phase' is the parent and 'Release Task' is the child table.

The state should be 'ready' until all the release tasks under the Release Phase are completed.  Then the user has an option to choose any state.  How can I achieve that? Thanks

find_real_file.pngfind_real_file.png

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Riyak,

so on related list record creation of release task state should be set to ready and should be readonly

so you can have this through UI policy; make it onload type as well

condition as state is ready; UI Policy action as readonly true for that field.

I assume you will create release task using new button from related list and you fill the details on form and hit update it should redirect to the release phase form

for populating state as ready write after insert business rule on release task table and set the state as below

script:

var releasePhase = current.<phaseField>.getRefRecord(); // I assume there is 1 field on release task table which stores release phase

releasePhase.state = ''; // use proper choice value for ready state

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,

When the related list Release Task is created, the state in Release Phase (parent) should be set to ready and read-only not on Release Task record (child).

saiiaskumar
Mega Guru

Create Business rule on Release Tasks Table;

Business Rule :

When : After

Insert : True

Condition : Parent.State is Not Ready

 

Script : 

var gr = new GlideRecord("release_phase");//Release Phase table name
gr.get(current.u_release_phase);//Get The parent sys id - Use back end name of reference field pointing to parent
gr.state = "ready";//Back end value of ready choice
gr.update();

 

Create one more Business Rule on Release Task Table : 

Business Rule : Updating parent state when all child tasks is completed

When : After

 

Update : True

Condition : Parent.State is Ready and State changes to Complete//Release Phase in Ready State and Release Task is Completing

 

Script : 

var gr = new GlideRecord("release_phase");  //Release Phase table name


gr.addQuery("sys_id",current.u_release_phase); //Get parent sys id

gr.addQuery("state","!=","Completed");//Use backend value of choice completed

gr.query();

if(gr.getRowCount == 0){


gr.state = "new State";//Set any new Choice
gr.update();

 }

 

Write ACL or Onload Client Script or UI Policy to make State it read only

 

Client Script or UI Policy :

State is Ready

g_form.setReadOnly("state",true);

Field ACL on State field :

//Restrict in form level and list level

script : 

answer = true;

if(current.state == "ready"){

answer = false;

}

The first BR didn't work, below is my code.

var gr = new GlideRecord("Release");
gr.get(current.rm_release);
gr.state = "2";
gr.update();