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

Jeff Currier
ServiceNow Employee
ServiceNow Employee

Your question does not make sense.  I think you need to re-write this to be clear.  

In your example above, the second step doesn't do anything to change the third step.   In step two you say you select one of those columns, but in step three you show all records from the table.  If you are showing all records, are you only showing that one column?

Also, in step one, not all tables have a short description, so do you want to filter by tables which only have short description?

Is your desired result to have a form to do this?  How many tables do you really want to look through?  Incident, problem, change?  What beyond that?  Projects, SIR, etc?  What type of user would be looking through all tables, picking columns to ultimately see a short description.  Seems like a horrible user experience and I suspect you will have access control issues where most users will not be able to see either the table, column or short description.  Maybe more information on the use case and what you are trying to achieve may help.  

Thanks Jeff .... you are too intelligent LOL

Jeff Currier
ServiceNow Employee
ServiceNow Employee

I didn't intend any disrespect, I just couldn't follow what you were trying to achieve.

Fully agreed with you Jeff!! Question doesn't make any sense.

Thank you,
Abhishek Gardade