- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2024 06:24 AM
Hello everyone!
I have this requirement:
On the incident table, I have to populate de DESCRIPTION field when the Configuration Item is filled or changes. (it appends at the end of the description). And the following data from the selected Configuration Item should appear:
- Name
- IP Address
- Operating system
- Support Group
The activity stream should show the change.
Any idea?
Thanks to all!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2024 08:53 AM - edited ‎03-04-2024 08:54 AM
Hi @Servinho Deve ,
You can create a onChange client script and Script include to achieve this ,
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sysId = g_form.getValue('cmdb_ci');
alert(sysId);
var ga = new GlideAjax('getConfigurationItem');
ga.addParam('sysparm_name','getCi');
ga.addParam('sysparm_id', sysId);
ga.getXML(getResponse);
}
function getResponse(response){
var ans = response.responseXML.documentElement.getAttribute('answer');
alert(ans);
g_form.setValue('description',ans);
}
Script include:
Check client callable to true
var getConfigurationItem = Class.create();
getConfigurationItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCi: function() {
var sysId = this.getParameter('sysparm_id');
gs.info("line number 6 " + sysId);
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_id', sysId);
var arr = [];
gr.query();
if (gr.next()) {
arr.push("Asset tag: "+gr.asset_tag +'\n' + "Serial number: " +gr.serial_number );
}
gs.info("line number 14 " + arr);
return arr.toString();
},
type: 'getConfigurationItem'
});
Result:
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2024 06:36 AM
First need to bring these field on form level
Then you can write the BR , to append teh changes in Description, but it depends on length of description, if more than 40 characters it will not accept.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2024 08:53 AM - edited ‎03-04-2024 08:54 AM
Hi @Servinho Deve ,
You can create a onChange client script and Script include to achieve this ,
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sysId = g_form.getValue('cmdb_ci');
alert(sysId);
var ga = new GlideAjax('getConfigurationItem');
ga.addParam('sysparm_name','getCi');
ga.addParam('sysparm_id', sysId);
ga.getXML(getResponse);
}
function getResponse(response){
var ans = response.responseXML.documentElement.getAttribute('answer');
alert(ans);
g_form.setValue('description',ans);
}
Script include:
Check client callable to true
var getConfigurationItem = Class.create();
getConfigurationItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCi: function() {
var sysId = this.getParameter('sysparm_id');
gs.info("line number 6 " + sysId);
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_id', sysId);
var arr = [];
gr.query();
if (gr.next()) {
arr.push("Asset tag: "+gr.asset_tag +'\n' + "Serial number: " +gr.serial_number );
}
gs.info("line number 14 " + arr);
return arr.toString();
},
type: 'getConfigurationItem'
});
Result:
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2024 09:01 AM - edited ‎03-04-2024 09:18 AM
@Servinho Deve in the above make a small change in client script so that it will not replace existing description, it will append it
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sysId = g_form.getValue('cmdb_ci');
alert(sysId);
var ga = new GlideAjax('getConfigurationItem');
ga.addParam('sysparm_name','getCi');
ga.addParam('sysparm_id', sysId);
ga.getXML(getResponse);
}
function getResponse(response){
var ans = response.responseXML.documentElement.getAttribute('answer');
alert(ans);
var desc = g_form.getValue('description');
g_form.setValue('description', desc+'\n' +ans);
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang