Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideRecord Query with UI Macro

Sathya10
Tera Expert

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;amp;topicName=' + g_form.getValue('number') +': ' + g_form.getValue('short_description') + '&amp;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

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

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;amp;topicName=' + g_form.getValue('number') +': ' + g_form.getValue('short_description') + '&amp;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

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

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

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 

it should work provided the field name is valid

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