scriptinclude and onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 12:29 AM
In cmdb_ci_business_app table if i select Application name (group reference)then the owner (user reference) of that group should auto populated.
Can u please explain code in detail.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 12:52 AM
Hi @Mahesho11
You can give the getReference a try.
getReference(String fieldName, Function callBack)
Sample OnChange Script of the Group field (make sure you're using the correct field name)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.clearValue('owner'); //your owner field name
return;
}
g_form.getReference('group', populateOwner); //your gorup field name
}
function populateOwner(group) { // reference is passed into callback as first arguments
g_form.setValue('owner', group.getValue('manager')); //your owner field name
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 09:41 AM
Please provide me script include only. I need to show.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 07:49 PM
Hi @Mahesho11
There you go.
#OnChange Client Script (table cmdb_ci_business_app and the group reference field)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.clearValue('owner'); //your owner field name
return;
}
var ga = new GlideAjax('BusinessAppUtilAjax');
ga.addParam('sysparm_name', 'getGroupManager');
ga.addParam('sysparm_group_id', newValue);
ga.getXMLAnswer(function(answer){
if(answer != ''){
g_form.setValue('owner', answer); //your owner field name
}
});
}
#Script Include (make sure the Client callable checkbox is checked)
var BusinessAppUtilAjax = Class.create();
BusinessAppUtilAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupManager: function(){
var groupID = this.getParameter('sysparm_group_id');
var managerID = '';
var grGroup = new GlideRecord('sys_user_group');
if(grGroup.get(groupID)){
managerID = grGroup.getValue('manager');
}
return managerID;
},
type: 'BusinessAppUtilAjax'
});
Cheers,
Tai Vu