SP.ScriptUtility Class

Applies to: SharePoint Foundation 2010

Provides methods and an emptyString field for working with ECMA scripts.

SP.ScriptUtility

Example

The following example creates an input button on an application page that displays information about specified strings.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

function runCode() {
    var emptyString = SP.ScriptUtility.emptyString;
    var notEmptyString = "hello";
    var dbl = 3.1415;
    var undefinedObject;

    if(SP.ScriptUtility.isNullOrEmptyString(emptyString)){
        alert('string is empty');
    }
    if(!SP.ScriptUtility.isNullOrEmptyString(notEmptyString)){
        alert('string is not empty');
    }
    alert(SP.ScriptUtility.truncateToInt(dbl));
    if (SP.ScriptUtility.isNullOrUndefined(undefinedObject)) {
        alert('object is undefined');
    }
    else {
        alert('object is defined');
    }
   
}
</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

See Also

Reference

SP.ScriptUtility Fields

SP.ScriptUtility Methods

SP Namespace