Copy Functionality for submitted RITM on My request page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 02:00 AM
I'm working on a Service Portal widget that displays "My Requests" and need to implement a Copy functionality for specific catalog items (iPhone 13 Pro). The requirement is:
- Show a "Copy" button beside RITMs for iPhone 13 Pro catalog items
- When clicked, redirect to the catalog item form
- Auto-populate the new form with variable values from the original RITM - REQUIRED FUNCTIONALITY
Below is the current widget scripts I have implemented for copy button and redirection. Need to update the logic to copy variables from RITM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 04:59 PM - edited 07-13-2025 05:08 PM
@baba, To achieve this you need to fetch the Server side data and map them to your client script as example below then create one OnLoad Client script for that catalog on which you wish to populate the copied fields.
HTML :
<div class="copy-but" ng-if="item.cat_item === 'Major Request'">
<button><a class="btn btn-primary" ng-click="c.redirectToCatalog()">Copy RITM</a></button>
</div>
Client Script :
c.redirectToCatalog = function () {
var catalogVariable1 = c.data.requestedFor;
var catalogVariable2 = c.data.state; // fetch this data from Server Script and map the field variables of your catalog that you wish to auto populate on RITM form that will load on click. Add as many as you need to auto populate. Then append the below URL with its variables. See example.
var url =
"https://dev186937.service-now.com/sp?id=sc_cat_item&sys_id=d4601ca7dbf6511062717f93f39619cr+$sysparm_catalogVariable1=catalogVariable1+$sysparm_catalogVariable2=catalogVariable2";
window.open(url);
};
OnLoad Client Script to fetch the data from the URL that you created above : *Don't change the function getParameterValue(). Use it as is. It fetches the values from your URL.
function onLoad() {
var catalogVariable1 = getParameterValue(catalogVariable1);
var catalogVariable2 = getParameterValue(catalogVariable2);
g_form.setValue("variable1", catalogVariable1);
g_form.setValue("variable2", catalogVariable2); // Whatever number of variable values you pulled from Widget, set them all like this.
}
function getParameterValue(name) {
name = name.replace(/[[]/, "\\[").replace(/[\]]/, "\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(top.location);
if (results == null) {
return "";
} else {
return decodeURI(results[1]);
}
}
Let me know if it helped!
PS - I created this about 2 years ago. Some syntax issues may arise. But most of it is correct. Double check the syntax and it should work.
Regards,
Vikas K