Skip to main content

Hello All,

I  have a requirement where in i need to create a Card under Support Portal. When we click on the card, it should take us to the Web page which should give users an option to select the products like Different kind of laptops and accessories. Once they select it, and submit it, it should raise a service request. 

 

I have tested my html java script on a machine, it should well. But when i am keeping it on Footer and saving it, it shows Scripting has been restricted to avoid spam.

Script portion that gives that error is below 

 

<script>
    let cart = c];
    
    // Function to add items to the cart
    function addToCart(name, price) {
        cart.push({ name, price });
        updateCartDisplay();
    }

    // Function to update cart display
    function updateCartDisplay() {
        const cartItemsDiv = document.getElementById('cart-items');
        cartItemsDiv.innerHTML = '';
        let total = 0;

        cart.forEach((item, index) => {
            total += parseFloat(item.price);
            const itemDiv = document.createElement('div');
            itemDiv.textContent = `${item.name} - $${item.price}`;
            const removeButton = document.createElement('button');
            removeButton.textContent = 'Remove';
            removeButton.classList.add('remove-item');
            removeButton.onclick = () => removeFromCart(index);
            itemDiv.appendChild(removeButton);
            cartItemsDiv.appendChild(itemDiv);
        });

        document.getElementById('total-price').textContent = `Total Price: $${total.toFixed(2)}`;
    }

    // Function to remove items from the cart
    function removeFromCart(index) {
        cart.splice(index, 1);
        updateCartDisplay();
    }

    // Add event listeners to buttons
    document.querySelectorAll('.item button').forEach(button => {
        button.addEventListener('click', () => {
            const price = button.getAttribute('data-price');
            const name = button.getAttribute('data-name');
            addToCart(name, price);
        });
    });

    // Submit Order function
    document.getElementById('submit-order').addEventListener('click', async () => {
        const requestorName = document.getElementById('requestor-name').value;
        const requestedFor = document.getElementById('requested-for').value;
        const newHireReason = document.getElementById('new-hire-reason').value;

        // Prepare ticket payload
        const ticketPayload = {
            ticket: {
                subject: `Order from ${requestorName}`,
                description: `Items ordered:\n${cart.map(item => `${item.name} - $${item.price}`).join('\n')}\n\nRequested For: ${requestedFor}\nReason: ${newHireReason}`,
                priority: 2, // Medium priority
                status: 2, // Open status
                category_id: 123456 // Replace with actual category ID
            }
        };

        // Make the API call to Freshservice
        try {
            const response = await fetch('https://yourdomain.freshservice.com/api/v2/tickets', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': 'Basic ' + btoa('API_KEY:') // Replace with your API key
                },
                body: JSON.stringify(ticketPayload)
            });

            if (response.ok) {
                alert('Order submitted successfully!');
                // Reset cart and form
                cart = o];
                updateCartDisplay();
                document.getElementById('requestor-name').value = '';
                document.getElementById('requested-for').value = '';
                document.getElementById('new-hire-reason').selectedIndex = 0;
            } else {
                alert('Failed to submit order: ' + response.statusText);
            }
        } catch (error) {
            alert('Error: ' + error.message);
        }
    });
</script>
 

That’s a restriction applied by Freshworks. Reach out to your TAM and they can enable scripting in the portal. 


Reply