move selected records from list view to another table.

Soma Sekhar M
Tera Contributor

Here is my List view of table.

SomaSekharM_0-1670406188996.png

 

On top I added a UI action button Order Now , my requirement is after selecting records if i click on Order Now button the selected record details have to be captured in another table. How can we achieve with script or configuration .

1 ACCEPTED SOLUTION

@Soma Sekhar M Please use below code:

 

UI Action:

function order() {
if (g_list.getChecked().toString().length > 0) {
var ga = new GlideAjax('Order');
ga.addParam('sysparm_name', 'orderNow');
ga.addParam('sysparm_checked_records', g_list.getChecked());
ga.getXML();
}
}

 

Script include:

var Order= Class.create();
UpdateAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
orderNow: function() {
var checkedRecords = this.getParameter('sysparm_checked_records');

var books = new GlideRecord('x_881103_book_cart_books');
books.addQuery('sys_idIN'+checkedRecords);
books.query();
while (books.next()) {
var targetTable = new GlideRecord("<TARGET TABLE HERE>");
targetTable.initialize()
//Set the fields here like beow
targetTable.<FIELD NAME> = books.<FIELD NAME HERE>; //Do mapping of field here
targetTable.insert();
}
},
type: 'UpdateAttachment'

});

 

jaheerhattiwale_0-1670411435480.png

 

 

Note: modify the script include function to map the fields from source and target table

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

4 REPLIES 4

jaheerhattiwale
Mega Sage
Mega Sage

@Soma Sekhar M 

1. UI Action should be a client type

2. In UI Action you just get the selected records by "g_list.getChecked()". It will give you comma separated list of selected records

3. Create a client callable script include

4. In UI Action, using GlideAjax pass the selected records to client callable script include function

5. Glide record on same table and query with selected records

6. In while loop transfer the each row to the another table

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi Jaheer, Thanks for your swift response with help of your guidelines I got the selected records sys_id now how we can write the code I am not getting? As I am very new to development Could you please provide the script to get an idea. 

 

SomaSekharM_0-1670410163937.png

 

SomaSekharM_1-1670410188232.png

 


thanks In advance 

@Soma Sekhar M Please use below code:

 

UI Action:

function order() {
if (g_list.getChecked().toString().length > 0) {
var ga = new GlideAjax('Order');
ga.addParam('sysparm_name', 'orderNow');
ga.addParam('sysparm_checked_records', g_list.getChecked());
ga.getXML();
}
}

 

Script include:

var Order= Class.create();
UpdateAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
orderNow: function() {
var checkedRecords = this.getParameter('sysparm_checked_records');

var books = new GlideRecord('x_881103_book_cart_books');
books.addQuery('sys_idIN'+checkedRecords);
books.query();
while (books.next()) {
var targetTable = new GlideRecord("<TARGET TABLE HERE>");
targetTable.initialize()
//Set the fields here like beow
targetTable.<FIELD NAME> = books.<FIELD NAME HERE>; //Do mapping of field here
targetTable.insert();
}
},
type: 'UpdateAttachment'

});

 

jaheerhattiwale_0-1670411435480.png

 

 

Note: modify the script include function to map the fields from source and target table

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Thanks Jaheer It's working on my Instance.