How to get the value from the variable which is made by maintain item.

komal shetty
Tera Contributor
i have clone the SC Catalog Item widget and added this code for the button named download attachment but i want to download the attachment based on the selection of the choice from the asset category variable which is made by the maintain item named bulk upload and i want that whenever the user select the choice value the the value should match the condition and set the sys id and download the template but it is not working can anyone help to debug this code and get to my expected output.
 
 
HTML:

<div ng-class="{'flex-center attachment-height': options.native_mobile == 'true', 'flex-end': options.native_mobile != 'true'}">
<div class="btn-container" ng-if="data.isVisible">
<button class="sn-btn sn-btn-primary" ng-click="c.downloadTemplate()">
Download Template
</button>
</div>

Client Controller:
 
function test($scope, $http, spScUtil, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce, i18n, $timeout, $log, spAriaUtil, $document, spModal, $q, spAtf, $location, spAriaFocusManager, spSCNavStateManager, cabrillo, snAnalytics) {
    var c = this;
    // Extract sys_id from the URL
    var urlParams = new URLSearchParams($location.absUrl());
    var sysId = urlParams.get("sys_id");

    // Check if the sys_id matches the required value
    $scope.data.isVisible = sysId === "enter sys_id";
    c.selectedSysId = '';
    $scope.$watch(function() {
        return c.data.asset_category;
    }, function(value, oldValue) {
        if (value !== oldValue) {
            console.log("Asset Category changed:", oldValue, "→", value);

            if (value && value.toLowerCase() === 'data center it'.toLowerCase()) {
                c.selectedSysId = 'enter sys_id'; // Replace with actual Sys ID
                console.log("Sys ID set to:", c.selectedSysId);
            } else {
                c.selectedSysId = ''; // Reset if another category is selected
                console.log("Sys ID reset");
            }
        }
    });

    c.downloadTemplate = function() {
        console.log("Download button clicked. Selected Sys ID:", c.selectedSysId);

        if (!c.selectedSysId) {
            alert("Please select a valid Asset Category before downloading the template.");
            return;
        }

        var attachmentUrl = "sys_attachment.do?sys_id=" + c.selectedSysId;
        window.open(attachmentUrl, "_self");
    };
    };
3 REPLIES 3

Kieran Anson
Kilo Patron

Why have you cloned the whole widger rather than:

  1. Using an attachment variable which can present a default attachment
  2. Used a 'Custom with Label' variable to hold a widget - in your case, the button to click and download the attachment.

Both of these options apply to a single request item, not the entire mechanism that displays all catalog items

I don't want to download a attachment i am downloading a template which is already attached in the backend.

i just want the values from the variable name asset category which you can see in the image i have attached and the button is the extra part which i have created inside the widget and it is only visible for single reuqest item no issue in that.

 

I don't understand your update sorry.