Export (0) Print
Expand All

SP.FieldCurrency Class

SharePoint 2010

Last modified: July 27, 2010

Applies to: SharePoint Foundation 2010

Specifies a field that contains currency values.

SP.FieldCurrency

The following example creates an input button on an application page that adds a currency field to the Tasks list of the current site.

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

    var list;
    var newfield;
    function runCode() {
        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            var web = clientContext.get_web();
            this.list = web.get_lists().getByTitle("Tasks");
            this.newfield = this.list.get_fields().addFieldAsXml('<Field DisplayName=\'Currency\' Type=\'Currency\' />', true, SP.AddFieldOptions.defaultValue);
            this.newfield = clientContext.castTo(newfield, SP.FieldCurrency);
            this.newfield.set_currencyLocaleId(1033);
            this.newfield.update();
            clientContext.load(this.newfield);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {
        if (this.newfield.get_fieldTypeKind() == SP.FieldType.currency) {
            alert('Currency field added to Tasks list.');
        }
        else {
            alert('Error on adding');
        }
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

</script>

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

</asp:Content>
Show:
© 2014 Microsoft