Cloned Ticket Field widget should be visible only to one catalog item on service portal

Maruthi Ram
Tera Contributor

Hello all,

 

Under "Request Something" in the portal we have  different catalogs out of which one is a record producer. When any one of the catalog item is submitted   , we see the below details from Ticket Fields Widget.

MaruthiRam_0-1719597881521.png

 

Requirement is to remove the priority field for only one of the catalog item(in this case the record producer) , When record producer is submitted priority field should not be shown , for this i had cloned the ticket fields widget and made the changes , but the changes are applied to all the catalog items.

MaruthiRam_1-1719598085191.png

 

How can i attach the cloned widget to the record producer?

 

 

2 REPLIES 2

Tabassum22
Tera Guru

Hi @Maruthi Ram,

 

One way to achieve this is by adding a condition in the client controller of the cloned widget. You can set up a condition to hide the priority variable if the catalog item's sys_id matches that of the record producer. Otherwise, it should remain visible for other catalog items by default. Finally, attach the cloned widget to the ticket conversation. 

 

here is the code snippet for the logic

function($scope, $location) {
    // Retrieve the current catalog item ID
    var catalogItemId = $location.search().sys_id;

    // The sys_id of the record producer catalog item
    var recordProducerSysId = 'YOUR_RECORD_PRODUCER_SYS_ID';

    // Watch for changes in the catalog item ID
    $scope.$watch(function() {
        return $location.search().sys_id;
    }, function(newVal, oldVal) {
        if (newVal) {
            catalogItemId = newVal;

            // Check if the catalog item ID matches the record producer ID
            if (catalogItemId === recordProducerSysId) {
                // Hide the priority field for the record producer
                $scope.data.hidePriority = true;
            } else {
                // Show the priority field for other catalog items
                $scope.data.hidePriority = false;
            }
        }
    });
}

 

Ensure the HTML template uses the condition to hide the priority field

<div ng-if="!data.hidePriority">
    <!-- Your existing priority field HTML goes here -->
</div>

 

Please mark it helpful and try to give it a thumbs up if the above helps. Please accept the solution.

 

Thanks & Regards

Tabassum Sultana

James Chun
Kilo Patron

Hi @Maruthi Ram,

 

Have you considered using the standard_ticket page instead?

It looks like you are still using the old ticket page, with the standard_ticket page, you can easily configure what fields to display on the form per table/record without customizing the widget(s).

 

https://docs.servicenow.com/bundle/utah-platform-user-interface/page/build/service-portal/concept/st...

 

Cheers