Copy button in MRVS

dianemiro
Kilo Sage

Hi Everyone,

Does anyone here already implemented a Copy button in MRVS? Just simply copying the above row.

Thanks,
Diane

1 ACCEPTED SOLUTION

Manish Vinayak1
Tera Guru

Hi Diane,

I don't think there is a way to customize / modify the out of the box widget / section which renders the multi-row variable set. One option that you have is creating a UI Macro to read the last row entered in the MRVS and copy it to the next row.

You can refer to the answer in your other thread on how to set values to a MRVS using client script:

https://community.servicenow.com/community?id=community_question&sys_id=60a3680cdb3ebf4023f4a345ca96...

You can have client script in your UI Macro, to read the last line of the MRVS and add that as another line to it.

Sample Script:

//Considering the internal name of the multi row variable set is "mrvs"
//Get the array of variables
var mrvs = JSON.parse(g_form.getValue("mrvs"));
//Get the last row added
var lastRow = mrvs[mrvs.length-1];
//Copy that row as the next row
mrvs.push(lastRow);
g_form.setValue("mrvs", JSON.stringify(mrvs));

 

Hope this helps!

Cheers,

Manish

View solution in original post

13 REPLIES 13

Manish Vinayak1
Tera Guru

Hi Diane,

I don't think there is a way to customize / modify the out of the box widget / section which renders the multi-row variable set. One option that you have is creating a UI Macro to read the last row entered in the MRVS and copy it to the next row.

You can refer to the answer in your other thread on how to set values to a MRVS using client script:

https://community.servicenow.com/community?id=community_question&sys_id=60a3680cdb3ebf4023f4a345ca96...

You can have client script in your UI Macro, to read the last line of the MRVS and add that as another line to it.

Sample Script:

//Considering the internal name of the multi row variable set is "mrvs"
//Get the array of variables
var mrvs = JSON.parse(g_form.getValue("mrvs"));
//Get the last row added
var lastRow = mrvs[mrvs.length-1];
//Copy that row as the next row
mrvs.push(lastRow);
g_form.setValue("mrvs", JSON.stringify(mrvs));

 

Hope this helps!

Cheers,

Manish

Does anyone have a roadmap on MRVS?

Would be great to know what is coming so we are better informed as to whether we should customise or not.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

True, that would be helpful!

Hi Manish,

I appreciate your response. I tried to do this via OnChange client script and it is working as expected. Last row are being copied. But when I put this on a Macro, it is not working. Can you tell me what am I doing wrong? Thank you.

<button onclick="myFunction()">Copy Last Row</button>
<script>
  function myFunction(){
	//Get the array of variables
	var mrvs = JSON.parse(g_form.getValue("add_devices_mrvs"));
	//Get the last row added
	var lastRow = mrvs[mrvs.length-1];
	//Copy that row as the next row
	mrvs.push(lastRow);
	g_form.setValue("add_devices_mrvs", JSON.stringify(mrvs));
</script>