Share via


Ewa.BrowserUdfs.removeAll()

Applies to: apps for SharePoint | Excel Services | SharePoint Server 2013

Removes all browser user-defined functions (UDFs) from the page.

Ewa.BrowserUdfs.removeAll();

Return Value

None.

Example

The following code example shows how to remove all browser UDFs from the page. The code example assumes that you are working with an Excel Web Access Web Part on SharePoint Server 2013.

<script type="text/javascript">
    var ewa = null;

    // Add event handler for onload event.
    if (window.attachEvent) {
        window.attachEvent("onload", ewaOnPageLoad);
    }
    else {
        window.addEventListener("DOMContentLoaded", ewaOnPageLoad, false);
    }

    // Add event handler for applicationReady event.
    function ewaOnPageLoad() {
        Ewa.EwaControl.add_applicationReady(onApplicationReady);
    }

    function onApplicationReady(result) {
        ewa = Ewa.EwaControl.getInstances().getItem(0);
        var udfs = ewa.getBrowserUdfs();

        // Add the browser UDF, "DISCOUNT" to the page
        udfs.add("DISCOUNT", DISCOUNT, "Gives company discounted price.", false, false);
    }

    // UDF that returns a discount (6%) for orders with 
    // 100 or more items; otherwise it returns 0.
    function DISCOUNT(quantity, price) {
        var theDiscount = 0;
        var discountCost = 0;
        var initialAmount = 0;

        if (quantity >= 100) {
            initialAmount = quantity * price;
            // Apply the 6% discount
            theDiscount = initialAmount * 0.06;
            discountCost = initialAmount - theDiscount;
        }
        else {
            discountCost = initialAmount;
        }        
        return discountCost;
    } // End browser UDF, "DISCOUNT"

    function removeJsUdfs() {
        // Unregister all browser UDFs
        ewa.getBrowserUdfs().removeAll();
        // Recalc the workbook
        ewa.getActiveWorkbook().recalcAsync(recalcHandler);
    }

    function recalcHandler(asyncResult) {
        if (asyncResult.getCode() == 0) {
            alert("Workbook recalc successful!");
        }
        else {
            alert("Recalc failed with error message " + asyncResult.getDescription() + ".");
        }
    } // End recalcHandler
</script>
<input type="button" id="RemoveUDFs" value="Remove all UDFs" onclick="removeJsUdfs()" />

See also

Reference

Ewa.BrowserUdfs Object

Concepts

Ewa.BrowserUdfs Methods