
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 04:36 AM
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
I also share what other scripts I found for incident table, maybe someone will notice sth.
I looked for it here:
client scripts:
ui policies:
data policies:
business rules:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 06:48 AM
ok, just write below UI Policy and check.
UI policy Action with Company field with Readonly = true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 06:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 07:07 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 07:18 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 07:36 AM
ok, I changed the scope for global.But I don't see any steps in the article. It just explains what UI policy is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 07:45 AM
ok check this, https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/administer/form-administration/task/t_CreateAUIPolicy.html