Auto populate data of first field based on second field selection

Kumar147
Tera Contributor

I have two reference fields on a form. one is platform and second one is CMDB. platform field is getting data from data management table and CMDB is getting data from cmdb_ci table. data management table having a list field which is reference to CMDB. when CMDB field is filled, the platform which is linked to that same ci to be auto populated in first reference field. how can i do that.

Thanks in advance

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi @Kumar147 ,

 

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.

If you find it helpful, please mark my answer as correct so that it can useful to others.

 

Thanks & Regards,
Sumanth Meda

 

View solution in original post

3 REPLIES 3

Brian Lancaster
Tera Sage

Use getReference in a onChange client script for the CI field.

Sumanth16
Kilo Patron

Hi @Kumar147 ,

 

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.

If you find it helpful, please mark my answer as correct so that it can useful to others.

 

Thanks & Regards,
Sumanth Meda

 

Hello Sumanth,

Actually i want to limit the number of records displayed in reference qualifier using script include.