Email Script for Multi Row Variable Set returning only the sys_id

Edxavier Robert
Mega Sage

Hi, 

I am creating an approval email notification where I need to display the values of a multi row variable set. I created an email script but is only returning the sys_id. So far this is what I have

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here
	//Name of my multi row variable set is remove_group_members
	// Name of the variable is assignment_group
    var mrvs =" ";
    mrvs = current.sysapproval.variables.remove_group_members;
    var rowCount = mrvs.getRowCount();
    for (var i = 0; i < rowCount; i++) {
        var row = mrvs.getRow(i);
        template.print(row.assignment_group); 
    }
})(current, template, email, email_action, event);

 Here an example

EdxavierRobert_0-1670623908659.png

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Assuming the assignment_group variable within the MRVS is the type of reference, then that value will be stored as a sys_id which makes sense with what you are seeing.  I don't think you can dot-walk within the MRVS results so you need to do a GlideRecord on the sys_user_group table where the sys_id = row.assignment_group, then from the returned record use the Name field.  So something like this:

...
var row = mrvs.getRow(i);
var grp = new GlideRecord('sys_user_group');
grp.addQuery('sys_id', row.assignment_group);
grp.query();
if (grp.next()) {
    template.print(grp.name);
} 
...

 

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Assuming the assignment_group variable within the MRVS is the type of reference, then that value will be stored as a sys_id which makes sense with what you are seeing.  I don't think you can dot-walk within the MRVS results so you need to do a GlideRecord on the sys_user_group table where the sys_id = row.assignment_group, then from the returned record use the Name field.  So something like this:

...
var row = mrvs.getRow(i);
var grp = new GlideRecord('sys_user_group');
grp.addQuery('sys_id', row.assignment_group);
grp.query();
if (grp.next()) {
    template.print(grp.name);
} 
...

 

@Thanks @Brad Bowman  , 

That works perfectly!

Hi Brad,

Do you know is there a way to restrict to print just specifics row instead or printing all row. Let me give you more context, I have a catalog item to automate provisioning group in ServiceNow, If the requestor is not the manager of the group, I will be sending an approval email to the manager, but I only need to send the information of the row relevant to that group. Let's say a user is trying to update multiple groups and is not the same manager I just need the information for that particular group. In my flow I have a for each row action to go over each record and send an approval. 

EdxavierRobert_2-1670689940147.png

exam.PNG

Each user belongs to a different group

It sounds like you still want to be inside the for loop of the mail script so that each MRVS row is evaluated.  After the var row line, if there's a MRVS variable that relates to how you're making the print/no print decision you could put that in an if statement, then the rest of the lines in the if block, or if something on the group record relates to a Catalog Item or MRVS variable, then go ahead and do the GR, but inside the if(gr.next()) block add another evaluation to wrap the print line in so that it only does if it satisfies that condition.