- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 01:45 AM
Here is my List view of table.
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 .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 03:11 AM
@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'
});
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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 01:51 AM
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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 02:49 AM
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.
thanks In advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 03:11 AM
@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'
});
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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 04:02 AM
Thanks Jaheer It's working on my Instance.