How to make setReadOnly function work for client script

Beata I_owiecka
Kilo Guru

Hi,

I created a client script that is setting company field of an incident same as caller.company.

The problem is that I want to set company filed of an incident readOnly after that, and that's not working.

I searched for conflicting UI policies and scripts, but found none. And then I found a business rule that's doing the same but after saving or updating, deactivated it, but problem is still occurring. What else can I do? Maybe I overlooked sth? Please help.

 

my client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	var ga = new GlideAjax('UserCompany');   
    ga.addParam('sysparm_name', 'getUserCompany');   
	ga.addParam('sysparm_user_id', newValue);   
	ga.getXMLAnswer(function(answer){
		alert("answer: " + answer);
		g_form.setValue('company', answer);
		g_form.setReadOnly('company', true);
	});
}

my script include

var UserCompany = Class.create();
UserCompany.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	
	getUserCompany: function() {
		var userRecord = new GlideRecord('sys_user');
		var user_id = this.getParameter('sysparm_user_id');
		userRecord.get(user_id);
		var companyId = userRecord.company.sys_id.getDisplayValue();
		return companyId;
	},

    type: 'UserCompany'
});

 

business rule I found

find_real_file.png

find_real_file.png

I also share what other scripts I found for incident table, maybe someone will notice sth.

I looked for it here:

find_real_file.png

client scripts:

find_real_file.pngfind_real_file.png

ui policies:

find_real_file.png

data policies:

find_real_file.png

business rules:

find_real_file.pngfind_real_file.pngfind_real_file.pngfind_real_file.pngfind_real_file.pngfind_real_file.png

1 ACCEPTED SOLUTION

ok, just write below UI Policy and check.

find_real_file.png

UI policy Action with Company field with Readonly = true

 

View solution in original post

17 REPLIES 17

Harshad Wagh
Tera Guru

if you dont mark it yo readonly, does it set the value?

Thanks

Harshad

yes, it does.

As mentioned by @AnirudhKumar , if the field is mandatory it cannot be made readonly.

You have to make it non-mandatory.

Thanks

Harshad

I'm not sure about it. It doesn't look like it was mandatory (no asterisk by the field company as there is one by the "caller" and "short description" fields)

find_real_file.png

also adding this to a client script didn't help

	g_form.setMandatory('company', false);