How can I create a Variable editor that works like sc_req_item and sc_task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2019 07:48 PM
I found a very old post on this subject which helped me to create a variable editor which works on a single custom table.
Solution: clone the Incident variable editor and replace the table with your custom table.
The proposed solution works fine for a custom table, where I am still having difficulty is implementing this for a child task table.
I've also tried modifying the macro com_glideapp_questionset_default_question_editor, like this:
<?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"/>
<g2:evaluate var="jvar_catalog_item">
function eval_cat_item() {
var cat_item = "";
var className = current.getRecordClassName();
var catItemProducedGr = new GlideRecord("sc_item_produced_record");
if (className == "u_treasury_operations") {
catItemProducedGr.addQuery("record_key", current.getUniqueValue());
} else if(className == "u_treasury_operations_tasks") {
catItemProducedGr.addQuery("record_key", current.parent.getUniqueValue());
}
catItemProducedGr.query();
if (catItemProducedGr.next())
cat_item = catItemProducedGr.getValue("producer");
return cat_item;
}
eval_cat_item();
</g2:evaluate>
<!-- load only the one_to_one variable sets -->
<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.addQuery("variable_set.type", "one_to_one");
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}">
<j2:if test="$[jvar_catalog_item != '']">
<j2:set var="jvar_producer_target_record" value="true"/>
<g2:client_script type="catalog_question_editor" catalogItem="$[jvar_catalog_item]"/>
<g:inline template="catalog_ui_policy.xml"/>
<g2:render_component componentName="com.glideapp.servicecatalog.DefaultQuestionEditor"/>
</j2:if>
<j2:if test="$[jvar_catalog_item == '']">
<!--Render old default editor if catalog item is not found -->
<g2:render_component componentName="com.glideapp.questionset.DefaultQuestionEditor"/>
</j2:if>
</div>
</j:jelly>
This doesn't break the form and variables are displayed on the parent record but not on the child task.
Parent record:
Child task record with the same variable editor:
- Labels:
-
Scripting and Coding
- 2,579 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2020 03:32 PM
I need the same thing, were you able to find a way for the variables to appear in the child record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 01:37 PM
Please review the entry provided on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2023 04:41 AM
Hi Kent,
Have you found any work around for this. If you have got any solution can you please help me. I am facing similar issue
Thanks,
Harshavardhan
I have 2 custom tables:
One is extended from sm_order and this solution displays the variables on that form as desired.
The other table is extended from sm_task and is being used for tasks related to the first table in a related list (like sc_req_item and sc_task). I can't figure out how to get a variable editor on the child task table to show the variables of the parent record.
I have tried combining the logic in com_glideapp_questionset_default_question_editor and com_glideapp_servicecatalog_veditor but can't get this to work.
Can anyone provide help with this?
Here is my edited macro based on com_glideapp_servicecatalog_veditor:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j2:if test="$[current.canRead()]">
<g:requires name="scripts/js_includes_catalog.js" includes="true"/>
<g:requires name="styles/${new CatalogCssSelector().getVariableCss()}" includes="true"/>
<g2:evaluate var="jvar_catalog_item">
function eval_cat_item() {
var cat_item = "";
var className = current.getRecordClassName();
if (className == "u_treasury_operations") {
cat_item = current.u_cat_item;
} else if (className == "u_treasury_operations_tasks") {
cat_item = current.parent.u_cat_item;
}
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.addQuery("variable_set.type", "one_to_one");
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>
<j2:if test="$[jvar_catalog_item != '']">
<div data-sn-macro-sys-id="${jvar_macro_sys_id}">
<g2:client_script type="catalog_question_editor" catalogItem="$[jvar_catalog_item]"/>
<g:inline template="catalog_ui_policy.xml" />
<g2:render_component componentName="com.glideapp.servicecatalog.VEditor"/>
</div>
</j2:if>
</j2:if>
</j:jelly>
This macro breaks the form, all fields below this variable editor are not displayed and no variables are displayed:
My variable editor in the form layout immediately below the description field:
Variable editor removed from the form layout:
I see the same issue on the child task form, can anyone help me to get this working?