UI macro variable: Copy data from one mrvs to another
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 11:27 AM
Hi team,
I had a requirement to copy some fields from one mrvs to another mrvs within catalog task. So I had created a custom variable with UI macro which uses g_form.setValue & JSON.stringify to set data in destination mrvs. The macro works but it reloads the page and when page reloads, the desination mrvs looses the data and its empty.
Anyway I can prevent UI macro to not reload or cancel reload? or any alternate solution to copy data from one mrvs to another in a catalog item.
Regards,
Sharad
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 07:29 PM
Hi,
can you share your relevant scripts and screenshots
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 06:17 AM
Below is the setup I was able to recreate the issue in my personal Dev instance. Same macro works well on catalog item intake form. But on catalog task, it refresh on click and I loose new data in MRVS2:
Below is the macro 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">
<style>#copy_recs { background-color: #278efc; color: #ffffff;}</style>
<button id="copy_recs" onClick="fillMRVS2();">Copy from MRVS1 to MRVS2</button>
<script>
function fillMRVS2() {
var mvrs1Str = g_form.getValue('mrvs1');
var mvrs1Obj = JSON.parse(mvrs1Str);
var mvrs2Obj = [];
for (var i=0; i < mvrs1Obj.length; i++) {
var tempObj = {};
tempObj.field4 = mvrs1Obj[i].field1;
tempObj.field5 = mvrs1Obj[i].field3;
mvrs2Obj.push(tempObj);
}
g_form.setValue("mrvs2", JSON.stringify(mvrs2Obj));
g_form.save();
}
</script>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 01:17 PM
Note: Maroonbyte = Sharad Patel 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2022 08:59 PM
Did you try to add alert and check what comes in MRVS?
you can try to query and get RITM variable value
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>#copy_recs { background-color: #278efc; color: #ffffff;}</style>
<button id="copy_recs" onClick="fillMRVS2();">Copy from MRVS1 to MRVS2</button>
<script>
function fillMRVS2() {
var mvrs1Str = g_form.getValue('mrvs1');
alert(mvrs1Str);
// query RITM with g_form.getValue('request_item') if you are on sc_task form
var mvrs1Obj = JSON.parse(mvrs1Str);
var mvrs2Obj = [];
for (var i=0; i < mvrs1Obj.length; i++) {
var tempObj = {};
tempObj.field4 = mvrs1Obj[i].field1;
tempObj.field5 = mvrs1Obj[i].field3;
mvrs2Obj.push(tempObj);
}
g_form.setValue("mrvs2", JSON.stringify(mvrs2Obj));
g_form.save();
}
</script>
</j:jelly>
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader