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.

Export button on Engagement form

BKash
Tera Contributor

Hello, I have to create an export UI action on engagement form. When I click on it, it will export the excel view of the test plans report which has the current details of the associated test plans to that engagement. How can I achieve this??

1 REPLY 1

Priscilla Muiua
ServiceNow Employee
ServiceNow Employee

Hi @BKash ,

 

1. Create a UI Action on the Engagement Form

  • Table: sn_audit_engagement

  • Form button: checked

  • Client: checked 

  • Name: Export Test Plans

  • Order: as preferred

  • Onclick: exportTestPlansExcel();
  • Script:
function exportTestPlansExcel() {
var engagementSysId = g_form.getUniqueValue();
 
var ga = new GlideAjax('TestPlanExportHelper');
ga.addParam('sysparm_name', 'getTestPlanSysIds');
ga.addParam('sysparm_engagement', engagementSysId);
 
ga.getXML(function(response) {
var testPlanSysIds = response.responseXML.documentElement.getAttribute("answer");
if (testPlanSysIds) {
var encodedQuery = 'sys_idIN' + testPlanSysIds;
var url = '/sn_audit_test_plan_list.do?sysparm_query=' + encodedQuery;
url += '&sysparm_view=default';
url += '&sysparm_target=sn_audit_test_plan';
url += '&CSV';
g_navigation.openPopup(url);
} else {
alert('No Test Plans found for this Engagement.');
}
});
}

2.Create a script include

Create a client callable script include named TestPlanExportHelper with the below script
var TestPlanExportHelper = Class.create();
TestPlanExportHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTestPlanSysIds: function() {
var engagementSysId = this.getParameter('sysparm_engagement');
var testPlanSysIds = [];
 
var gr = new GlideRecord('sn_audit_m2m_test_plan_engagement');
gr.addQuery('sn_audit_engagement', engagementSysId);
gr.query();
while (gr.next()) {
testPlanSysIds.push(gr.getValue('sn_audit_test_plan'));
}
gs.info('testPlanSysIds '+testPlanSysIds);
return testPlanSysIds.join(',');
},
 
type: 'TestPlanExportHelper'
});
PriscillaMuiua_0-1746196872592.png