The CreatorCon Call for Content is officially open! Get started here.

Issue to add Variable editor in child tasks

Suvitha Murugan
Tera Contributor

Hi everyone,

I'm trying to display the Variable Editor on the Change Task table in ServiceNow, similar to how it's shown on the Change Request table. The variables are defined on the parent Change Request via a catalog item or record producer, and I want those variables to be visible and editable from the associated Change Task.

I attempted to configure a UI Macro and Formatter to render the variable editor on the Change Task form, but I haven’t been able to get it working correctly. I suspect the issue might be with how the macro references the parent record or retrieves the catalog item.

Could anyone guide me on:

  • How to properly configure the UI Macro for the Change Task table?
  • Whether there’s a recommended way to display variables from the parent Change Request?
  • Any alternative approaches to achieve this?

Any help or examples would be greatly appreciated!

Thanks in advance!



UI Macro:

<?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.parent);
        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('change_request');
            recordObject.get(current.parent);
        </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>

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Suvitha Murugan 

I won't recommend showing the variable editor on child task as agent can anyhow navigate to parent and see the variables in variable editor.

this link has solution

Variable editor on child task(other than catalog task) 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for your response, @Ankur Bawiskar.

I’ve reviewed the documentation you shared, and I’m currently trying to configure the Variable Editor on my Change Task table. However, I’m unable to replicate the Variable Editor setup that exists on the Change Request table. I’m specifically having trouble configuring the UI Macro to work correctly with my task table.

Could you please guide me on how to properly reference the parent record and display its variables in the task form? Any insights or examples would be greatly appreciated!

Note: In my setup, the parent field on the Change Task table is referencing the Task table, not directly the Change Request table. Because of this, I'm having difficulty configuring the Variable Editor to display variables from the Change Request. 

@Suvitha Murugan 

It should work fine.

change_task table has the field change_request which holds CHG and not parent field.

So you should update code as this

catItemProducedGr.addQuery("record_key", current.change_request);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader