
- 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 08:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 09:44 AM
I guess you were creating the client script in your scope, just for test if you can create the client script in global scope and test?
Thanks
Harshad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 04:45 AM
I guess you have created a new field called Company on the incident table?
If so, that is not required. You could bring the caller's company field by simply dot-walking on the incident form. That way you do not need autopopulate it nor do you have to make it readonly. Both would automatically happen.
Anyway, you setReadOnly script looks alright to me.
just try this silly alternative:
g_form.setReadOnly('company', 'true');
If that doesn't work, then i guess your company field is mandatory, which is why system is unable to make it readonly, coz that would be conflict

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 04:59 AM
Hi AnirudhKumar,
No, I havent created the Company field, it's a core field of an incident table.
It's also required, I have to auto-populate it by a client script onChange, that's my task requirement.
g_form.setReadOnly('company', 'true');
I already tried this alternative, but didn't worked.
Thanks for feedback!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 05:14 AM
Use Form-Layout and bring the dot-walked company field on the form and use this onChange() client script which is on caller_id field, it should work for you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('caller_id', callBack);
function callBack(gr){
g_form.setReadOnly('gr.company', true);
}
}