- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2019 03:34 AM
Hi Everyone,
Does anyone here already implemented a Copy button in MRVS? Just simply copying the above row.
Thanks,
Diane
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2019 06:44 PM
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:
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2019 03:34 PM
Hi Diane,
Sorry for the delayed response on this one. Strangely, didn't get any notification about this response by ServiceNow.
Anyway, were you able to resolve the issue?
If not, just wanted to check you had created UI Macro, as well as a widget to be associated with the Macro variable. As UI Macro contains Jelly code which doesn't work on Service Portal.
Regards,
Manish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2019 05:26 PM
You are missing a closing brace:
<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>
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2019 06:31 PM
Oh yeah. Nice catch Paul !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2019 06:40 AM
Hi Diane,
I am looking for the same functionality. I've not done anything with UI macros before, so I'm not sure how to use the script in this post.
Could you show how you achieved this.
Thanks
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2019 07:39 AM
Hi Samogden,
Create UI Macro with script:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<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>
</j:jelly>
Then create a variable with Type Macro and use the macro name created above.