- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-25-2024 02:20 AM
Hello,
I would like to auto populate a field in the target catalog item with the request name of the source catalog item when clicking a link within the Description field.
I saw the steps in the post below and created an onLoad client script, but unable to retrieve the value from the previous catalog item:
Pre-populate a record producer form after clicking link on the catalog item
The target catalog item has a Reference field that refers sc_cat_item table. I want to auto-fill this field based on the source catalog item from which the link was clicked.
Has anyone implemented a similar feature or can guide me on how to achieve this?
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2024 12:25 AM
Solved error using "location.hash" this in client script!
var url = location.hash;
If possible, I want to automatically fetch sysid of the Test Catalog Item12, rather than directly set the sysid in the URL in the description...But that seems difficult.
If anyone knows of any way to do this, I would appreciate it if you could REPLY to me.
For the time being, the title issue has been resolved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-25-2024 02:31 AM
how have you defined the link? have you included some URL parameter in it?
if yes then did you use onLoad catalog client script on your Test Catalog Item inquiry catalog item to get value from url and set in that variable?
if yes then only it will work fine.
If not then you need to create one.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-25-2024 04:23 AM
Hi @E555 ,
To achieve the functionality of auto-populating a field in the target catalog item with the name of the source catalog item when clicking a link within the description field, you can utilize URL parameters and client scripts. This method allows the source catalog item to pass relevant information to the target catalog item upon redirection.
Modify the description field of the source catalog item to include a clickable link that directs users to the target catalog item. Pass the name or sys_id of the source catalog item as a URL parameter. Here's an example:
<a href="/com.glideapp.servicecatalog_cat_item_view.do?sys_id=<TARGET_CATALOG_ITEM_SYS_ID>&source_item_name=${current.name}">
Click here to proceed to the next item
</a>
Replace <TARGET_CATALOG_ITEM_SYS_ID> with the sys_id of the target catalog item. The ${current.name} placeholder dynamically inserts the name of the source catalog item.
now
In the target catalog item, create an onLoad client script to read the URL parameter and populate the desired field. The script retrieves the source item's name from the URL and sets it in the Reference field.
(function executeRule(gForm, gSNC, gUser) {
// Helper function to get URL parameter by name
function getParameterByName(name) {
var url = window.location.href;
name = name.replace(/[[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
var results = regex.exec(url);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Retrieve the source item name from the URL
var sourceItemName = getParameterByName("source_item_name");
// If the parameter exists, populate the Reference field
if (sourceItemName) {
gForm.setValue("reference_field_name", sourceItemName);
}
})(gForm, gSNC, gUser);
here :The getParameterByName function extracts the source_item_name parameter from the URL.
The gForm.setValue function populates the Reference field (reference_field_name) with the extracted name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2024 07:50 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2024 07:58 PM
It would be helpful if you could take a look at my latest reply.
The following is not available and gives me an error:
var url = window.location.href;