Need to get form variables on HR case

rog
Giga Contributor

Hi All,

 

I have created a record producer on the HR application which will create a HR case.Now I need all the variables on the record producer to be coming in the HR case as Form variables. Im not sure how to get that.

 

Can anyone help?

2 REPLIES 2

Kalaiarasan Pus
Giga Sage

Try this 

https://docs.servicenow.com/bundle/london-it-service-management/page/product/service-catalog-management/task/configure-default-variable-editor.html

XI LUJUN
Tera Contributor

You can get all the Form variables and values from the table 'question_answer' by 'table_sys_id' which is the sys_id of the HR case.

In the table, the 'question' column is the sys_id of the Form variables and the values can be saved as string or sys_id in the 'value' column.

When the value of Form variables is saved by sys_id, you can click the question's link to see the 'Type Specifications' which can know where to get the true values.

For example, a question named 'Employee Name' is saved as sys_id in the table 'question_answer'. It's type is Reference and the reference table is sys_user.
So you can get the true value record in table 'sys_user' by sys_id which is the value of question 'Employee Name'.

By this case, you can use code like this:

	var gr = new GlideRecord('question_answer');
	
	gr.addQuery('table_sys_id',sysId);  // 'sysId' is the sys_id of HR case
	gr.addActiveQuery();
	gr.orderBy('order');
	gr.query();
	
	while(gr.next()) {
		var value = gr.value.toString();
		
		// When the question type is Reference
		var refGr = new GlideRecord(gr.question.reference);  // Get the reference table
		if(refGr.get(value)) {
			value = refGr.getDisplayValue();
		}
	}