- 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.