Create new table records on clicking ui action button from another table

Sharath807
Tera Contributor

So I have a requirement ,when I select list of records in list view in  table A and click ui action button (Approve) those records should be transferred and create new record in Table B, Also those records in table A should updated status as approved. How to achieve this.

10 REPLIES 10

Community Alums
Not applicable

Hi @Sharath807

I tried on list view now please use below script it is working fine for me 

function funcList() {
    var selectedIds = g_list.getChecked();
    var ids = selectedIds.split(',');

    alert('status - ' + ids.length);

    for (var i = 0; i < ids.length; i++) {
	alert("Inside for loop = " + i);
        var gr = new GlideRecord('incident');
        gr.initialize();
        gr.short_description = "Test 12345";
        gr.insert();
    }
}

SarthakKashyap_0-1718361103712.png

 

Result 

SarthakKashyap_1-1718361193236.png

There are two button on my Case table when I selected both the record and click on UI Action it creates two record in Incident table 

Before 475 Records

SarthakKashyap_2-1718361241208.png

After 477 Records

SarthakKashyap_3-1718361265851.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

 

@Community Alums Hi when i click approve button its showing popup as.
Screenshot (2).png

Community Alums
Not applicable

Hi @Sharath807 ,

That was an alert, you can remove that. Script will work in that case also.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Sanket Landge
Tera Expert

hello @Sharath807,

 

You can use : 

 

var selSysIds = g_list.getChecked();

 

variable selSysIds will have comm separated list of sysIds of selected records and then you can use those sysId while creating records in another table using below code

var sysIdList = selSysIds.split(',');

alert('status - '+selSysIds);

for (var i=0;i<=sysIdList.length;i++)

{

var gr = new GlideRecord('sys_approver');

gr.initialize();

gr.sys_id = -1;

gr.doucment_id = sysIdList[i];

//other mandatory fileds

gr.insert();

}

 

Use loop for creation of record.

 

Please mark helpful/correct if this helped.

 

Regards,

Sanket Landge

@Sharath807,

 

Have you checked this?