GlideRecord Query with UI Macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2022 09:59 PM
Hi All,
I'm trying to implement a feature that allows the user to open a group chat with the assignment group members with the click of a button.
I'm trying to query the sys_user_grmember table with the assignment group info on the ticket to get the email of the members to append to the Teams deep link URL
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core"
xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<a class="btn-default;" id="${jvar_n}" onclick="invokeChat('${ref}');">
<img src="teams.png" width="25" title="Teams Chat" alt="${gs.getMessage('Click to open Teams chat')}" />
</a>
<g:evaluate var="jvar_gr" object="true">
var gr = new GlideRecord('sys_user_grmember');
var assign_grp = g_form.getValue('assignment_group');
gr.addQuery('group',assign_grp);
gr.query();
while(gr.next()){
user += gr.user.email + ',';
}
user;
</g:evaluate>
<script>
function invokeChat(reference) {
var prefix = 'https://teams.microsoft.com/l/chat/0/0?users=';
var firstname = g_form.getReference('u_requestor').first_name;
var user1 = jelly.jvar_gr;
var subject = '&amp;topicName=' + g_form.getValue('number') +': ' + g_form.getValue('short_description') + '&amp;message=Hi All, Can you please give me an update ?';
var w = getTopWindow();
var url = prefix + user1 + subject;
w.open(url);
}
</script></j:jelly>
It looks like the g_form object is not defined in the evaluate section. Any assistance will be deeply appreciated.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2022 10:38 PM
Hi,
that's correct g_form won't work in g:evaluate as g:evaluate is server side
You can use current object
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core"
xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<a class="btn-default;" id="${jvar_n}" onclick="invokeChat('${ref}');">
<img src="teams.png" width="25" title="Teams Chat" alt="${gs.getMessage('Click to open Teams chat')}" />
</a>
<g:evaluate var="jvar_gr" object="true">
var gr = new GlideRecord('sys_user_grmember');
var assign_grp = current.getValue('assignment_group'); // use current object here
gr.addQuery('group',assign_grp);
gr.query();
while(gr.next()){
user += gr.user.email + ',';
}
user;
</g:evaluate>
<script>
function invokeChat(reference) {
var prefix = 'https://teams.microsoft.com/l/chat/0/0?users=';
var firstname = g_form.getReference('u_requestor').first_name;
var user1 = jelly.jvar_gr;
var subject = '&amp;topicName=' + g_form.getValue('number') +': ' + g_form.getValue('short_description') + '&amp;message=Hi All, Can you please give me an update ?';
var w = getTopWindow();
var url = prefix + user1 + subject;
w.open(url);
}
</script></j:jelly>
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 12:11 AM
Hi Ankur,
I'm getting the following error:
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in ftp://gsft_database/teams_chat.7 at line 3
1:
2: var gr = new GlideRecord('sys_user_grmember');
==> 3: var assign_grp = current.getValue('assignment_group');
4: gr.addQuery('group',assign_grp);
5: gr.query();
6: while(gr.next()){
Kindly advice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022 12:03 AM
Hi Ankur,
Kindly advice on if there is a way to dynamically use the assignment group value on the form in the evaluate section of the jelly script
Regards,
Sathya R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2022 08:49 AM
it should work provided the field name is valid
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader