How to make a field readonly

Sathwik1
Tera Expert

When an incident task is created then I need to make some fields[one field named test] readonly on incident...how can I achieve it?

and one more condition is.... the same field I had in incident task....even though incident having readonly..if I update something on incident task it needs to update on incident even it is readonly

Note: copying functionality is already written

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Sathwik,

 

You can use a display business rule & onLoad() client script as below.

1. Display Business rule on Incident table as below

(function executeRule(current, previous /*null when async*/ ) {

        var chkincidentask = new GlideRecord('incident_task');
        chkincidentask.addQuery('parent', current.sys_id); //considering parent field contais child incident number
        chkincidentask.query();
        if (chkincidentask.next()) {
            g_scratchpad.haschild = 'true';
        }
	

})(current, previous);

2. onLoad() client script on Incident table as below.

function onLoad() {
   if(g_scratchpad.haschild=='true')
		{
			alert('yes'); //for check you can comment it
			g_form.setReadOnly('opened_at',true);
			g_form.setReadOnly('description',true); //mention your fields you want to set read-only accordingly

		}
   
}

View solution in original post

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

You will have to create a onLoad client script and call a GlideAjax to query the incident task table and if a record exists, return true. and make records readonly.

 

The other option is to make it read only using access control on incident table


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

Jaspal Singh
Mega Patron
Mega Patron

Hi Sathwik,

 

You can use a display business rule & onLoad() client script as below.

1. Display Business rule on Incident table as below

(function executeRule(current, previous /*null when async*/ ) {

        var chkincidentask = new GlideRecord('incident_task');
        chkincidentask.addQuery('parent', current.sys_id); //considering parent field contais child incident number
        chkincidentask.query();
        if (chkincidentask.next()) {
            g_scratchpad.haschild = 'true';
        }
	

})(current, previous);

2. onLoad() client script on Incident table as below.

function onLoad() {
   if(g_scratchpad.haschild=='true')
		{
			alert('yes'); //for check you can comment it
			g_form.setReadOnly('opened_at',true);
			g_form.setReadOnly('description',true); //mention your fields you want to set read-only accordingly

		}
   
}

@Jaspal Singh 

If I make readonly by using above mentioned code...

then If I updated on incident task[Test field] will it get update in incident? 

                 (or)

as it is read only[Test field in incident table] it will not get changed?

 

Note: copying functionality was already returned 

If I make readonly by using above mentioned code...

then If I updated on incident task[Test field] will it get update in incident? 

No, it will still remain read-only. If you closely look it uses simply on-Load client script.

                 (or)

as it is read only[Test field in incident table] it will not get changed?

All depends how are you copying & updating. Ideally, it should work unless you have some field level ACLs configured additionally.