Macro g2:render_component - Component name

Rafael Pinto
Tera Contributor

Hello. In the jelly code of the UI macro "com_glideapp_servicecatalog_veditor" (used in the "Variable Editor" formatter of the sc_req_item and sc_task tables), I believe the line below renders a component which displays the variables in the formatter:

 

<g2:render_component componentName="com.glideapp.servicecatalog.VEditor"/>

 

My question is: can this component named "com.glideapp.servicecatalog.VEditor" be found in any table in ServiceNow? Or is it just the name of the UI Macro written in a slightly different way?

 

Thank you.

6 REPLIES 6

Maik Skoddow
Tera Patron
Tera Patron

Hi

no, the code of that component is not accessible.

But maybe you want to explain why you want to have the code? What is your underlying business requirement?

Kind regards
Maik

Hello, Maik.

We have created a table extending the task table (it's called Service table) in its own scope. Some record producers create records in this table, and each one has an associated flow.

Creating a variable editor formatter for this table was straightforward: I just followed the instructions on the ServiceNow docs.

 

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

 

The problem is, some of those Service records have catalog tasks associated to them. This formatter I created for the Service table does not work on the SCTASK form, i.e. it does not show the variables. I believe the reason is, the "com_glideapp_questionset_default_question_editor" UI Macro gets the catalog item through the following function:

 

function eval_cat_item() {
var cat_item = "";
var catItemProducedGr = new GlideRecord("sc_item_produced_record");
catItemProducedGr.addQuery("record_key", current.getUniqueValue());
catItemProducedGr.query();
if (catItemProducedGr.next())
cat_item = catItemProducedGr.getValue("producer");
return cat_item;
}

 

I tried modifying the third line inside the function to

catItemProducedGr.addQuery("record_key", current.universal_request.getUniqueValue());

But to no avail, as well as some other adjustments.

The requirement is, not configuring the formatter for a task-extended table, but rather to the sc_task table when its parent ticket does not come from sc_req_item but from another task-entended table. I'm trying to leverage the already existing code in ServiceNow, but eventually I will have to write a new UI Macro from scratch.

Rafael Pinto
Tera Contributor

Hello. I found a workaround. I'm presenting the issue below with an example and the workaround used.

 

I created the custom table Generic Request extending the Task table and the Record Producer Open a generic request.

find_real_file.png

In the flow for this Record Producer, a Catalog Task is created and associated to the Generic Request record using the Universal Request field.

find_real_file.png

I created two formatters, one for the Generic Request Table and another one for the Catalog Task table. Both of them use the com_glideapp_questionset_default_question_editor UI Macro.

find_real_file.png

find_real_file.png

So far so good. Both formatters were included in the Generic Request and Catalog Task forms through Form Layout. In the Generic Request record, the variables are shown.

find_real_file.png

The problem is, the variables are not shown on the Catalog Task form.

find_real_file.png

The issue was how to make the variables be shown in the Catalog Task form. There is the possibility of creating a new UI Macro from scratch, which would be a huge effort. However, there is a workaround in order to show the variable by using the available OOB UI Macro.

Two tables are involved: Question Answer [question_answer], which stores the answers provided for the variables in a record created by a record producer, and Item Produced Record [sc_item_produced_record], which link a record created by a Record Producer to the Record Producer used to create it.

In the example above, when the Generic Request was created, a record was created in the sc_item_produced_record table linking the record GEN0001002 the the Open a generic request Record Producer, and two records in the question_answer table storing the value of the two variables.

The workaround consists in creating copies of those records, but linked to the SCTASK. In order to do so, a business rule was created in the sc_task table. It will run when a record is inserted and its universal request number begins with GEN.

find_real_file.png

find_real_file.png

(function executeRule(current, previous /*null when async*/) {
	
	var qa = new GlideRecord('question_answer');
	qa.addQuery('table_sys_id',current.universal_request.sys_id.toString());
	qa.addQuery('table_name','u_generic_request');
	qa.addQuery('question.global',true);
	qa.addQuery('value','!=','');
	qa.query();
	while(qa.next()) {
		var gr = new GlideRecord('question_answer');
		gr.initialize();
		gr.table_name = 'sc_task';
		gr.table_sys_id = current.sys_id.toString();
		gr.question = qa.question.sys_id.toString();
		gr.value = qa.value;
		gr.order = qa.order;
		gr.insert();		
	}
	
	var pr = new GlideRecord('sc_item_produced_record');
	pr.addQuery('record_table','u_generic_request');
	pr.addQuery('producer',current.universal_request.item.sys_id.toString());
	pr.addQuery('record_key',current.universal_request.sys_id.toString());
	pr.addQuery('task',current.universal_request.sys_id.toString());
	pr.query();
	if(pr.next()) {
		var pt = new GlideRecord('sc_item_produced_record');
		pt.initialize();
		pt.record_table = 'sc_task';
		pt.producer = current.universal_request.item.sys_id.toString();
		pt.record_key = current.sys_id.toString();
		pt.task = current.sys_id.toString();
		pt.insert();		
	}
	
})(current, previous);

With this business rule, the variables are shown in the SCTASK form.

find_real_file.png

 

A few points:

 

  • The query value != '' in the GlideRecords could be left out, but if the goal is to solely show those variables which were filled by the end user, it makes no difference.
  • This workaround does not work retroactively on previous tasks, but a scheduled job on demand with a very similar script can be used for that end.
  • If any changes are made to a variable value in one of the forms, it will not be reflected on the other one (e.g. if the Please describe your request variable value is modified in the GEN form, the value shown in the SCTASK form will remain the old one), because there are two independent question_answer records. If all variables are read-only on the forms, it will not make a difference, as they cannot be changed, However, if that is not the case, a business rule in the question_answer table in order to synchronize the records would solve the issue.

Community Alums
Not applicable

Thanks, the workaround helped! This is what I was looking for.