0

I have a syntax error on the code below, all I want is a function to be executed on a call back but I am not sure what the error is.

should be close to:

onClickCallback: UpdateBillCycleStatusToCompleted(1)

<script type="text/javascript">
    SP.SOD.executeFunc("callout.js", "Callout", function () {
        var itemCtx = {};
        itemCtx.Templates = {};
        itemCtx.BaseViewID = 'Callout';
        // Define the list template type
        itemCtx.ListTemplateType = 101;
        itemCtx.Templates.Footer = function (itemCtx) {
            // context, custom action function, show the ECB menu (boolean)
            return CalloutRenderFooterTemplate(itemCtx, AddCustomCompleteAction, true);
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);
    });

    function AddCustomCompleteAction(renderCtx, calloutActionMenu) {
        // Add your custom action
        calloutActionMenu.addAction(new CalloutAction({
            text: "Custom Action",
            tooltip: 'This is your custom action',
            onClickCallback: UpdateBillCycleStatusToCompleted(1)
        }
        }));

    // Show the default document library actions
    CalloutOnPostRenderTemplate(renderCtx, calloutActionMenu);

    // Show the follow action
    calloutActionMenu.addAction(new CalloutAction({
        text: Strings.STS.L_CalloutFollowAction,
        tooltip: Strings.STS.L_CalloutFollowAction_Tooltip,
        onClickCallback: function (calloutActionClickEvent, calloutAction) {
            var callout = GetCalloutFromRenderCtx(renderCtx);
            if (!(typeof (callout) === 'undefined' || callout === null)) callout.close();
            SP.SOD.executeFunc('followingcommon.js', 'FollowSelectedDocument', function () {
                FollowSelectedDocument(renderCtx);
            });
        }
    }));
    }

    function UpdateBillCycleStatusToCompleted(itemId) {
        alert('Completed');
        //var clientContext = new SP.ClientContext.get_current();
        //var oList = clientContext.get_web().get_lists().getByTitle('Bill Cycles');
        //this.oListItem = oList.getItemById(itemId);
        //oListItem.set_item('Bill Cycle Preparation Status', 'Completed');
        //oListItem.update();
        //clientContext.executeQueryAsync(Function.createDelegate(this, this.StatusCompletedSucceeded), Function.createDelegate(this, this.StatusCompletedFailed));
    }

    function StatusCompletedSucceeded() {
        alert('Item updated!');
    }

    function StatusCompletedFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
</script>
2
  • what is onClickCallback: UpdateBillCycleStatusToCompleted(1) and why is it out the the script block? Commented Mar 2, 2014 at 15:53
  • You need to pass a callback function, which means you must not call it Commented Mar 2, 2014 at 15:54

1 Answer 1

1

Unless UpdateBillCycleStatusToCompleted(1) actually return function() {...} then you're doing it wrong.

onClickCallback: function() {UpdateBillCycleStatusToCompleted(1);}

That sort of thing should work.

Sign up to request clarification or add additional context in comments.

1 Comment

I still have this error: SyntaxError: Unexpected token }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.