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

ok, just write below UI Policy and check.

find_real_file.png

UI policy Action with Company field with Readonly = true

 

sorry, I'm a newbie to servicenow, do you mean:

create a new UI policy action with Company field Readonly = true

or maybe 

create a new UI policy to check if Company field Readonly = true

I can't create UI Policy with incident  table,  I just can choose tables from my application scope.

Looks like it's restricted by default to create UI policy on fields from core tables in a scoped app. 

Well you need to change the scope of your development to global if you are making any changes to table which is out of your scope.

once done, juts following below steps.

https://developer.servicenow.com/dev.do#!/learn/learning-plans/sandiego/new_to_servicenow/app_store_learnv2_scripting_sandiego_ui_policies

 

Thanks

Harshad

ok, I changed the scope for global.But I don't see any steps in the article. It just explains what UI policy is.

ok check this, https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/administer/form-administration/task/t_CreateAUIPolicy.html