How to use the customized widget for a particular catalog item only in service portal?

venky18
Tera Contributor

Hi All,

I need to create a new widget but it has to work only for particular catalog item only in service portal? Can anyone help in this ??

1 REPLY 1

Riya Verma
Kilo Sage
Kilo Sage

Hi @venky18 ,

 

Hope you are doing great.

You can create you own new widget and attach it to particular catalog item by modifying the existing widget using below reference steps:

  1. In the widget editor, write the code to define the behavior and functionality of your new widget. 

 

<div>
  <h2>New Widget</h2>
  <p>This widget is specifically designed for the desired catalog item.</p>
  <!-- Add your custom code here -->
</div>

 

  • To restrict the widget to the desired catalog item, you can utilize the widget's server script (if needed) or the client-side JavaScript code. Here's an example of how you can achieve this using Javascript&colon;
    var itemId = 'sys_id_of_catalog_item'; // Replace with the sys_id of the desired catalog item
    
    // Get the current catalog item ID from the URL or any other suitable method
    var currentItemId = g_form.getValue('sysparm_item_guid'); // Example: accessing through g_form
    
    if (itemId === currentItemId) {
      // Show or enable the widget's content
      document.getElementById('widget-container').style.display = 'block';
      // Add any other custom logic specific to the desired catalog item
    } else {
      // Hide or disable the widget's content
      document.getElementById('widget-container').style.display = 'none';
      // Add any other custom logic for other catalog items if needed
    }
  •  Save the widget and add it to the desired Service Portal page

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma