- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 03:18 PM
Hi all,
I am trying to pass values from a ui macro to my incident form.
Values I am trying to pass: category (reference field) and area (string field)
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:evaluate var="jvar_is_ST" expression="gs.hasRole('Service Teams')" />
<j:if test="${jvar_is_ST == true }">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="change_cat_area_SD_${jvar_guid}:${ref}"/>
<a>
<span id="${jvar_n}" onclick="changeCatAreaPop('${ref}')"
class="btn btn-default icon-add-circle"
title="${gs.getMessage('Change Category and Area')}"
alt="${gs.getMessage('Change Category and Area')}">
</span>
</a>
<script>
//OnClick function for UI macro
function changeCatAreaPop(reference){
//Get the name of the field referenced by this macro
var s = reference.split('.');
var referenceField = s[1];
var v = g_form.getValue(referenceField);
//Pop up the window
var dialog = new GlideDialogForm('Change Category and Area', 'incident', setCatField);
dialog.setSysID('-1'); //Pass in -1 to create a new record
dialog.addParm('sysparm_view', 'category_and_area');
dialog.addParm('sysparm_form_only', 'true'); //Remove related lists
dialog.render(); //Open the dialog
//Callback function executed from dialog submit
function setCatField(action, sys_id, table, displayValue) {
//Set the fields with the category
g_form.setValue(referenceField, sys_id); //--> this is not working...
}
}
</script>
</j:if>
</j:jelly>
The dialog window pops up however:
1. the category chosen in it is not passed to the form. The category field on the form empties.
2. how do I also pass the area parameter from the dialog window to the form?
Thanks
harel
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2017 02:48 PM
So I found the solution, but feel free to suggest a better one:
1. Created another table with category and area
2. changed the UI Macro to pop up that table
3. on submit of the form, ran a query on the table to find the related record
4. populated the category and area on the incident form, from that new table
My UI Macro looks 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:evaluate var="jvar_is_ST" expression="gs.hasRole('Service Teams')" />
<j:if test="${jvar_is_ST == true }">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="change_cat_area_SD_${jvar_guid}:${ref}"/>
<a>
<span id="${jvar_n}" onclick="changeCatAreaPop('${ref}')"
class="btn btn-default icon-add-circle"
title="${gs.getMessage('Change Category and Area')}"
alt="${gs.getMessage('Change Category and Area')}">
</span>
</a>
<script>
//OnClick function for UI macro
function changeCatAreaPop(reference){
//Get the name of the field referenced by this macro
var s = reference.split('.');
var referenceField = s[1];
var v = g_form.getValue(referenceField);
var inc = g_form.getUniqueValue();
//Pop up the window
var dialog = new GlideDialogForm('Change Category and Area', 'u_inc_cat_area_lookup', setCatField);
dialog.setSysID('-1'); //Pass in -1 to create a new record
dialog.addParm('sysparm_query','u_incident='+inc); //Set form sys id in incident field
dialog.addParm('sysparm_view', 'default_view'); //Specify a form view
dialog.addParm('sysparm_form_only', 'true'); //Remove related lists
dialog.render(); //Open the dialog
//Callback function executed from dialog submit
function setCatField(action, sys_id, table, displayValue) {
//Set the fields with the popup user
var l = new GlideRecord(table);
l.addQuery('u_incident', g_form.getUniqueValue());
l.query();
if(l.next()) {
g_form.setValue(referenceField, l.u_category);
g_form.setValue('u_area', l.u_area);
l.deleteRecord();
}
}
}
</script>
</j:if>
</j:jelly>
Perhaps not elegant, but working.
Feel free to suggest a better solution, or problems with this one.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 03:54 PM
Hi Harel,
Thread below should help you address the issue by doing
dialog.setLoadCallback(function(iframeDoc) {
// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
dialogFrame.g_form.setValue('u_requested_by', reqcust);
dialogFrame.g_form.setValue('u_task_number', tasknum);
dialogFrame = null;
});
Pass values when calling a GlideDialogForm with a UI Action
But alternatively, if the macro can be split for each individual field, you can create a seperate macro and refer it in the column dictionary
so something like category dictionary would
'ref_contributions=category_chosen'
Create a UI macro category_chosen and then inside the 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:evaluate var="jvar_is_ST" expression="gs.hasRole('Service Teams')" />
<j:if test="${jvar_is_ST == true }">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="change_cat_area_SD_${jvar_guid}:${ref}"/>
<a>
<span id="${jvar_n}" onclick="changeCatAreaPop('${ref}')"
class="btn btn-default icon-add-circle"
title="${gs.getMessage('Change Category and Area')}"
alt="${gs.getMessage('Change Category and Area')}">
</span>
</a>
<script>
//OnClick function for UI macro
function changeCatAreaPop(reference){
//Get the name of the field referenced by this macro
var s = reference.split('.');
var referenceField = s[1];
var v = g_form.getValue(referenceField);
//Pop up the window
var dialog = new GlideDialogForm('Change Category and Area', 'incident', setCatField);
dialog.setSysID('-1'); //Pass in -1 to create a new record
dialog.addParm('sysparm_view', 'category_and_area');
dialog.addParm('sysparm_form_only', 'true'); //Remove related lists
dialog.render(); //Open the dialog
}
</script>
</j:if>
</j:jelly>
I know the above alternative has worked with GlideDialogwindow but never tried with GlideDialogForm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 04:44 PM
Hi Venkat,
Thank you for the answer.
(I see that the title of the discussion is misleading, though. It should say glideDialogForm.)
The thing is, I am trying to get values from the glideDialogForm and not into it.
Seems like I have to get the values of the field in the callback function, but I am not sure how to do that. And then use g_form.setValue to set the incident form with the values from the glideDialogForm.
If that's not possible, is it possible to call a client script or a script include from a UI Macro? Maybe they can generate the glideDialogWindow and then I guess it is possible to do some manipulation on the data once it is passed to the form.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2017 01:50 PM
bernyalvarado? abhinay ? anyone? suggestions on how to proceed? maybe what I am trying to do is not possible this way?
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2017 02:48 PM
So I found the solution, but feel free to suggest a better one:
1. Created another table with category and area
2. changed the UI Macro to pop up that table
3. on submit of the form, ran a query on the table to find the related record
4. populated the category and area on the incident form, from that new table
My UI Macro looks 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:evaluate var="jvar_is_ST" expression="gs.hasRole('Service Teams')" />
<j:if test="${jvar_is_ST == true }">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="change_cat_area_SD_${jvar_guid}:${ref}"/>
<a>
<span id="${jvar_n}" onclick="changeCatAreaPop('${ref}')"
class="btn btn-default icon-add-circle"
title="${gs.getMessage('Change Category and Area')}"
alt="${gs.getMessage('Change Category and Area')}">
</span>
</a>
<script>
//OnClick function for UI macro
function changeCatAreaPop(reference){
//Get the name of the field referenced by this macro
var s = reference.split('.');
var referenceField = s[1];
var v = g_form.getValue(referenceField);
var inc = g_form.getUniqueValue();
//Pop up the window
var dialog = new GlideDialogForm('Change Category and Area', 'u_inc_cat_area_lookup', setCatField);
dialog.setSysID('-1'); //Pass in -1 to create a new record
dialog.addParm('sysparm_query','u_incident='+inc); //Set form sys id in incident field
dialog.addParm('sysparm_view', 'default_view'); //Specify a form view
dialog.addParm('sysparm_form_only', 'true'); //Remove related lists
dialog.render(); //Open the dialog
//Callback function executed from dialog submit
function setCatField(action, sys_id, table, displayValue) {
//Set the fields with the popup user
var l = new GlideRecord(table);
l.addQuery('u_incident', g_form.getUniqueValue());
l.query();
if(l.next()) {
g_form.setValue(referenceField, l.u_category);
g_form.setValue('u_area', l.u_area);
l.deleteRecord();
}
}
}
</script>
</j:if>
</j:jelly>
Perhaps not elegant, but working.
Feel free to suggest a better solution, or problems with this one.
harel