Variable editor on child task(other than catalog task)
Hello Community,
Variable editors are really great way to show end user’s input to fulfillers. I get this question several times that, "hey Rahul, can we show variables on tasks other than catalog task" ?
Actually, there was a $500 bounty about this feature by @Robert Fedoruk 5 years ago. I was late to the party, 2 years late -_-
Let me give you an example, suppose, a requestor creates an incident via record producer. Out of the box, there is variable editor for task extended tables. Hence, you can show variable editor for target record of the record producer, in this case incident.
Reference of out of the box variable editor :https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-management/task/configure-default-variable-editor.html
However, what about incident task? What if fulfiller working on incident task would like to see user’s input? Navigate to incident every time ?
Below is a way to leverage UI macro to show variable editor on incident task
Example case,
User Rahul creates an incident using record producer
Record Producer
Resulting incident record
Incident task
Interesting right ? Let’s break this and find out how I have achieved it.
UI Macro
Name:CascadeFormatter
Script
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:requires name="scripts/js_includes_catalog.js" includes="true"/>
<g:requires name="styles/${new CatalogCssSelector().getVariableCss()}" includes="true"/>
<g:requires name="scripts/classes/ServiceCatalogForm.js"/>
<g2:evaluate var="jvar_catalog_item">
function eval_cat_item() {
var cat_item = "";
var catItemProducedGr = new GlideRecord("sc_item_produced_record");
catItemProducedGr.addQuery("record_key", current.incident);
catItemProducedGr.query();
if (catItemProducedGr.next())
cat_item = catItemProducedGr.getValue("producer");
return cat_item;
}
eval_cat_item();
</g2:evaluate>
<g2:evaluate var="jvar_cat_sets" jelly="true">
var jvar_cat_sets = "";
var gr = new GlideRecord("io_set_item");
gr.addQuery("sc_cat_item", jelly.jvar_catalog_item);
gr.query();
while (gr.next()) {
if (jvar_cat_sets.length > 0)
jvar_cat_sets += ",";
jvar_cat_sets += gr.variable_set;
}
jvar_cat_sets;
</g2:evaluate>
<div data-sn-macro-sys-id="${jvar_macro_sys_id}">
<g2:evaluate jelly="true"> var recordObject = new GlideRecord('incident');
recordObject.get(current.incident);
</g2:evaluate>
<j2:set var="ref" value="recordObject" />
<j:set var="jvar_producer_target_record" value="true"/>
<g2:client_script type="catalog_item" catalogItem="$[jvar_catalog_item]"/>
<g:inline template="catalog_ui_policy.xml"/>
<g2:render_component componentName="com.glideapp.servicecatalog.DefaultQuestionEditor"/>
</div>
</j:jelly>
Formatter
Screenshot:
Navigate to incident_task and add this formatter at the place of your choice
Hopefully, this article would help to those who are searching for a solution to this problem ![]()
https://www.servicenow.com/community/developer-articles/variable-editor-on-child-task-other-than-catalog-task/ta-p/2319268