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.

Create record from multiple selection in workspace list view

MaharshiC
Tera Contributor

Hi,

 

I have 2 custom tables in my workspace- order and item. Now in my order table there is one list field(selected items) which is reference to the item table i.e. one order is associated with multiple items. Now I have a requirement that somehow from my item table list view when the user selects multiple items and click on a button then a new record should be created in the order table having all the selected items in the list field(selected item) . Is this feasible to do from the list view?

1 REPLY 1

Shivalika
Mega Sage
Mega Sage

Hello @MaharshiC 

 

Yes this is possible, technically your requirement is to take certain action on multiple selected item on list view. 

 

For this create a Custom UI Action - give it some name and order and action. Make it available on list view as button or context menu whatever you want. 

 

In the script part add this - 

 

(function executeAction() {

    var gr = new GlideRecord('incident'); // Change table name as needed

    var selectedRecords = g_list.getChecked(); // Get selected records from list view

 

    if (!selectedRecords) {

        alert('Please select at least one record.');

        return;

    }

 

    gr.addQuery('sys_id', 'IN', selectedRecords); // Query selected records

    gr.query();

 

    while (gr.next()) {

        //Whatever action you want from them , in this case create a new order record and populate these items in list collector field - so that initialize the form and fill the values. 

 

        gr.update();

    }

 

    g_list.refresh(); // Refresh the list to reflect

changes

})();

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY