Location should be populated based on Configuration Item Selection

deepu805
Tera Contributor

Hi Team,

 

I have Location, Company and Configuration Item fields on Incident form, three are reference fields, My requirement is if i select Configuration Item, Location should be auto populated. If that CI doesn't have location data, company should be auto populated. Configuration Item record having company and location fields.

 

 

Thanks in Advance. 

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi @deepu805 .

 

You can set these fields using an onChange client script with the "Configuration item" (cmdb_ci) as the field name.

The following code is just an example of how you can retrieve data from the CI and populate the incident table using getReference:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	var ci = g_form.getReference("cmdb_ci", callBack);
}	
function callBack(ci){

	if (ci) {
		var cusSysId = ci.assigned_to; //assigned to user on the ci record
		var locSysId = ci.location; //ci location

		g_form.setValue("caller_id", cusSysId); //set caller with the user assigned to the ci
		g_form.setValue("location", locSysId); //set location based on ci location
	}
}

I personally prefer GlideAjax which has a client and server requirement to work. The benefit of using GlideAjax is that it only returns the data that you need rather than the whole record.

 

Plz mark my solution as Accept, If you find it helpful.

 

 

Thanks & Regards,

Sumanth meda

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

You can do this with an OnChange Client Script, if the requirement is to see the Location or Company field populate on the form immediately after a CI is selected.  If this immediacy is not needed, and/or a CI could be selected via other methods - list view, API, script, ... then a Business rule before Update and Insert on the incident table when Configuration item changes is a better approach.  There are numerous examples of each in this Community.  Give it a shot, then post your script using the insert code icon (</>) if you get stuck. 

Sumanth16
Kilo Patron

Hi @deepu805 .

 

You can set these fields using an onChange client script with the "Configuration item" (cmdb_ci) as the field name.

The following code is just an example of how you can retrieve data from the CI and populate the incident table using getReference:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	var ci = g_form.getReference("cmdb_ci", callBack);
}	
function callBack(ci){

	if (ci) {
		var cusSysId = ci.assigned_to; //assigned to user on the ci record
		var locSysId = ci.location; //ci location

		g_form.setValue("caller_id", cusSysId); //set caller with the user assigned to the ci
		g_form.setValue("location", locSysId); //set location based on ci location
	}
}

I personally prefer GlideAjax which has a client and server requirement to work. The benefit of using GlideAjax is that it only returns the data that you need rather than the whole record.

 

Plz mark my solution as Accept, If you find it helpful.

 

 

Thanks & Regards,

Sumanth meda