issue in custom action code

rmaroti
Tera Contributor

Hi everyone,

i have write code inside the custom action  script but it is showing error :
"Encountered undeclared output variable: platformAdminGroup"
and "Encountered undeclared output variable: uniqueActiveManagers."

Below is the code: In below code Im traying to to achieve all active unique manager associated to group and "platform_admin" group but getting above error but in background script getting expected error.

 

(function execute(inputs, outputs) {
   
var activeManagers = [];
 
// Initialize variable to store the platform_admin group record
 
var platformAdminGroup = null;
 
// Query the sys_user_group table to find the group with the name 'platform_admin'
 
var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('name', 'platform_admin'); // Or use sys_id if preferred
groupGR.query();
if (groupGR.next()) {
    platformAdminGroup = groupGR.getUniqueValue(); // Store the sys_id of the platform_admin group
}
 
// Query all active groups from the sys_user_group table
 
var activeGroupGR = new GlideAggregate('sys_user_group');
activeGroupGR.addQuery('active', true); // Only active groups
activeGroupGR.groupBy('manager');
activeGroupGR.query();
 
// Iterate through the active groups to find unique active managers
while (activeGroupGR.next()) {
 
        var managerId = activeGroupGR.getValue('manager');  // Get the manager's sys_id
        if (managerId && !activeManagers.includes(managerId)) {
            activeManagers.push(managerId);
        }
   }

// Set outputs
outputs.uniqueActiveManagers = activeManagers; // Return the list of unique active manager sys_ids
outputs.platformAdminGroup = platformAdminGroup; // Return the sys_id of the platform_admin group
 
})(inputs, outputs);
 
Output Variable in custom action below script:
rmaroti_0-1744280361086.png

 

rmaroti_1-1744280422678.png

 

 output of custom action execution in FD:

rmaroti_4-1744280703980.png

 

 

 

 

 

 

 

 

so how to set the output variable for above requirement can anyone please suggest

 

 

1 ACCEPTED SOLUTION

@rmaroti 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

J Siva
Tera Sage

Hi @rmaroti 

You need to update the output variable names. Try the below one.

(function execute(inputs, outputs) {
   
var activeManagers = [];
 
// Initialize variable to store the platform_admin group record
 
var platformAdminGroup;
 
// Query the sys_user_group table to find the group with the name 'platform_admin'
 
var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('name', 'platform_admin'); // Or use sys_id if preferred
groupGR.query();
if (groupGR.next()) {
    platformAdminGroup = groupGR.getUniqueValue(); // Store the sys_id of the platform_admin group
}
 
// Query all active groups from the sys_user_group table
 
var activeGroupGR = new GlideAggregate('sys_user_group');
activeGroupGR.addQuery('active', true); // Only active groups
activeGroupGR.groupBy('manager');
activeGroupGR.query();
 
// Iterate through the active groups to find unique active managers
while (activeGroupGR.next()) {
 
        var managerId = activeGroupGR.getValue('manager');  // Get the manager's sys_id
        if (managerId && !activeManagers.includes(managerId)) {
            activeManagers.push(managerId);
        }
   }

// Set outputs

outputs.activemanagers = activeManagers;// Return the list of unique active manager sys_ids
outputs.platformadmingroup = platformAdminGroup;// Return the sys_id of the platform_admin group
 
})(inputs, outputs);

Hope this helps.
Regards,
Siva

Ankur Bawiskar
Tera Patron
Tera Patron

@rmaroti 

you should use the exact output variable names as present in your script step

update these 2 lines with bold as correct output variable names

outputs.activemanagers= activeManagers; // Return the list of unique active manager sys_ids
outputs.platformadmingroup = platformAdminGroup; // Return the sys_id of the platform_admin group

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@rmaroti 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@rmaroti 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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