Share via


Ewa.BrowserUdfs.exists(udfName)

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

Gets a Boolean value that indicates whether the specified browser user-defined function (UDF) exists.

Ewa.BrowserUdfs.exists(udfName);

Parameters

udfName

Type: string

The name of the browser UDF.

Return Value

Type: boolean

true if the specified browser UDF exists; false otherwise.

Example

The following code example shows how to determine if a specific browser UDF exists. 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;
    }

    function removeJsUdf() {
        var name = document.getElementById("jsUdfName").value;
        // Check to see if browser UDF exists; if yes, remove/unregister
        if (ewa.getBrowserUdfs().exists(name)) {
            var isRemoved = ewa.getBrowserUdfs().remove(name);

            if (isRemoved) {
                alert("The browser UDF, " + name + " was successfully removed.");
            }
            else {
                alert("Unable to remove browser UDF, " + name + ".");
            }
        }
        else {
            alert("The browser UDF, " + name + " does not exist on this page.");
        }
    }
</script>
<input type="text" id="jsUdfName" />
<input type="button" id="RemoveJsUdf" value="Remove UDF" onclick="removeJsUdf()" />

See also

Reference

Ewa.BrowserUdfs Object

Concepts

Ewa.BrowserUdfs Methods