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.

UI Action in Related List

Toshikazu
Tera Contributor

I want to create a new UI Action in the related list of the x_nttl2_sales_supp_document_management table, which is displayed on the form of the x_nttl2_sales_supp_sales table.

 

Name: New Document

Map the following fields from x_nttl2_sales_supp_sales to the new x_nttl2_sales_supp_document_management record:

u_opportunity → u_opportunity_name

u_requester_sales → u_requester_sales

u_department → u_department

 

But no matter how well I try, I can't create a UI Action.

I often get the error "No Record Selected".

How can I create this UI Action?

 

Here's what I'm trying:

 

Condition: current.canCreate() && !RP.getListControl().isOmitNewButton() && RP.isRelatedList() && !RP.isOneToMany()

 

Script:

(function executeAction() {
// Check if the current table is 'x_nttl2_sales_supp_sales'
if (current.getTableName() != 'x_nttl2_sales_supp_sales') {
return;
}

// Create a new record in 'x_nttl2_sales_supp_document_management' table
var newRecord = new GlideRecord('x_nttl2_sales_supp_document_management');
newRecord.initialize();

// Map fields from 'x_nttl2_sales_supp_sales' to 'x_nttl2_sales_supp_document_management'
newRecord.u_opportunity_name = current.u_opportunity;
newRecord.u_requester_sales = current.u_requester_sales;
newRecord.u_department = current.u_department;

// Set 'u_order_classification' field to 'sales'
newRecord.u_order_classification = 'sales';

// Set reference to the parent record
newRecord.x_nttl2_sales_supp_sales = current.sys_id;

// Insert the new record
newRecord.insert();

// Redirect to the new record
action.setRedirectURL(newRecord);
})();

0 REPLIES 0