How to autopopulate a field based on two other fields ?

Rohan37
Giga Expert

find_real_file.png

 

First in that table field we select a table let's say it is incident table 

Second, in the column field we will only be shown the fields for that incident table  and we select one out of those  columns

Third, this field will show all the records from the incident table and when we select a record then it will show the content of its Short description of that record .... 

Note  that we assume that no matter what table we select that table contains a short description field. 

Thanks. 

Please help me out 

1 ACCEPTED SOLUTION

Rohan37
Giga Expert

BTW i finished  the work xD

// onChange ClientScript for table-field 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	
   //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('recordColumnContent');
	ga.addParam('sysparm_name', 'columnContent');
	ga.addParam('tableId', g_form.getValue('u_table'));
	ga.getXMLWait();
	var answer = ga.getAnswer();
 	alert(answer);
// 	ga.addParam('sysparm_name', )
// 	ga.addParam('currentColumn', g_form.getValue('u_column'));
	
}
/*----------------------------------------------------------------------------------- */

// onChange ClientScript for column-field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('recordColumnContent');
	ga.addParam('sysparm_name', 'gettingColumnValue');
	ga.addParam('currentColumn', g_form.getValue('u_column'));
	
	ga.getXMLWait();
}
/*------------------------------------------------------------------------------------ */

//The required script include : 

var recordColumnContent = Class.create();
recordColumnContent.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	columnContent: function()
	{
		gs.log('Entered Script Include', 8974);
		var tableId = this.getParameter('tableId');
		gs.log('Table sys_id :'+tableId, 8974);
		var tableName='';
		var dictionary = new GlideRecord('sys_dictionary');
		var sysDbObj = new GlideRecord('sys_db_object');
		sysDbObj.addQuery('sys_id', tableId);
		sysDbObj.query();
		//if(sysDbObj.next())
			//{
		sysDbObj.next();
				tableName = sysDbObj.name;
				gs.log('table name :'+sysDbObj.name, 8974);
		//	}
		
		dictionary.addQuery('element', 'u_content');
		dictionary.query();
		//if(dictionary.next())
			//{
		dictionary.next();
				gs.log('Current Table in Reference:'+dictionary.reference, 8974);
				dictionary.reference = sysDbObj.name;
				dictionary.update();
				gs.log('Reference After:'+dictionary.reference, 8974);
			//}
	},
	
	gettingColumnValue: function()
	{
		var currentColumn = this.getParameter('currentColumn');
		gs.log('The current Column'+currentColumn, 8972);
		var gr = new GlideRecord('sys_dictionary');
		gr.addQuery('sys_id', currentColumn);
		gr.query();
		gr.next();
		gr.display= true;
		gs.log('Display Value of the column'+gr.element+' is '+gr.display, 8972);
		gr.update();
	},
	
    type: 'recordColumnContent'
});

View solution in original post

6 REPLIES 6

Rohan37
Giga Expert

BTW i finished  the work xD

// onChange ClientScript for table-field 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	
   //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('recordColumnContent');
	ga.addParam('sysparm_name', 'columnContent');
	ga.addParam('tableId', g_form.getValue('u_table'));
	ga.getXMLWait();
	var answer = ga.getAnswer();
 	alert(answer);
// 	ga.addParam('sysparm_name', )
// 	ga.addParam('currentColumn', g_form.getValue('u_column'));
	
}
/*----------------------------------------------------------------------------------- */

// onChange ClientScript for column-field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('recordColumnContent');
	ga.addParam('sysparm_name', 'gettingColumnValue');
	ga.addParam('currentColumn', g_form.getValue('u_column'));
	
	ga.getXMLWait();
}
/*------------------------------------------------------------------------------------ */

//The required script include : 

var recordColumnContent = Class.create();
recordColumnContent.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	columnContent: function()
	{
		gs.log('Entered Script Include', 8974);
		var tableId = this.getParameter('tableId');
		gs.log('Table sys_id :'+tableId, 8974);
		var tableName='';
		var dictionary = new GlideRecord('sys_dictionary');
		var sysDbObj = new GlideRecord('sys_db_object');
		sysDbObj.addQuery('sys_id', tableId);
		sysDbObj.query();
		//if(sysDbObj.next())
			//{
		sysDbObj.next();
				tableName = sysDbObj.name;
				gs.log('table name :'+sysDbObj.name, 8974);
		//	}
		
		dictionary.addQuery('element', 'u_content');
		dictionary.query();
		//if(dictionary.next())
			//{
		dictionary.next();
				gs.log('Current Table in Reference:'+dictionary.reference, 8974);
				dictionary.reference = sysDbObj.name;
				dictionary.update();
				gs.log('Reference After:'+dictionary.reference, 8974);
			//}
	},
	
	gettingColumnValue: function()
	{
		var currentColumn = this.getParameter('currentColumn');
		gs.log('The current Column'+currentColumn, 8972);
		var gr = new GlideRecord('sys_dictionary');
		gr.addQuery('sys_id', currentColumn);
		gr.query();
		gr.next();
		gr.display= true;
		gs.log('Display Value of the column'+gr.element+' is '+gr.display, 8972);
		gr.update();
	},
	
    type: 'recordColumnContent'
});

FYI : getXMLWait is not at all rec commanded.

Thank you,
Abhishek Gardade