The CreatorCon Call for Content is officially open! Get started here.

Populate Description field with data from Configuration Item

Servinho Deve
Tera Contributor

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!

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage

Hi @Servinho Deve ,

 

You can create a onChange client script and Script include to achieve this ,

 

Client script:

swathisarang98_0-1709571094937.png

 

 

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 

swathisarang98_1-1709571155721.png

 

 

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:

swathisarang98_2-1709571251822.png

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Servinho Deve 

First need to bring these field on form level

AGLearnNGrow_0-1709562920539.png

 

AGLearnNGrow_1-1709562953894.png

 

 

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]

****************************************************************************************************************

swathisarang98
Giga Sage

Hi @Servinho Deve ,

 

You can create a onChange client script and Script include to achieve this ,

 

Client script:

swathisarang98_0-1709571094937.png

 

 

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 

swathisarang98_1-1709571155721.png

 

 

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:

swathisarang98_2-1709571251822.png

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

@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