Can we call catalog item based on the selection of a variable in another catalog item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 02:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 02:50 AM
What is your use case? What do you want to achieve?
What do you mean by 'call an item'? Do you want a conditional order guide? Do you want them to choose an option and be redirected to another item?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 02:53 AM
Hi Mark Manders,
I have a catalog item variable which is a select box(catalog item names). Based on the selection of select box we need to display variables belongs to selected catalog item on the same form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 12:12 AM
Check out the Order Guide.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 02:59 AM
Hi @srinureddy1642 ,
Using the Onsubmit() catalog client script and script includes.
Try this code
OnSubmit Client Script (To trigger the Script Include)
function onSubmit() {
var selectedService = g_form.getValue('service_type'); // Get the selected catalog item from the choice list
if (selectedService) {
// Call the Script Include (server-side) to create the RITM
var ga = new GlideAjax('CreateRITMFromChoice'); // GlideAjax to call Script Include
ga.addParam('sys_id', selectedService); // Pass the selected catalog item ID
ga.addParam('request_id', g_form.getValue('request')); // Pass the current request ID if available
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == 'success') {
// Success: you can display a message or perform other actions
alert('RITM created successfully!');
} else {
alert('Failed to create RITM.');
}
});
}
return true; // Continue with the form submission
}
Script Include
var CreateRITMFromChoice = Class.create();
CreateRITMFromChoice.prototype = Object.extendsObject(AbstractAjaxProcessor, {
createRITM: function() {
var selectedCatalogItem = this.getParameter('sys_id'); // Get the catalog item selected in the choice list
var requestId = this.getParameter('request_id'); // Get the current request ID
// Check if the required parameters are provided
if (selectedCatalogItem && requestId) {
var gr = new GlideRecord('sc_req_item'); // Create a new record in sc_req_item table
gr.initialize();
gr.request = requestId; // Link the RITM to the request
gr.cat_item = selectedCatalogItem; // Link the RITM to the selected catalog item
// Optional: Add other fields (e.g., variables, etc.) here if needed
gr.insert(); // Insert the RITM record into the sc_req_item table
return 'success'; // Return success to the client script
}
return 'failure'; // Return failure if parameters are missing
}
});