Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Javascript issues when creating an item.

$
0
0

I'm trying to get some JavaScript working to create an Task Item based on some other events on a page. I'm just learning but I've got the majority of what I want down. (I think.)

What I don't understand is why my task will create in one scenario and not in another.

function MarkAsRead() {
    console.log('MarkAsRead Function Ran');
    var ctxT = GetCurrentCtx();
    if (ctxT.listName = 'Documents') {
        //Get Context
        clientContext = new SP.ClientContext.get_current();
        //Get Web
        this.web = clientContext.get_web();
        //Get Current User
        currentUser = web.get_currentUser();
        clientContext.load(currentUser);
        //Get Selected Items
        items = SP.ListOperation.Selection.getSelectedItems(clientContext);

        //get workflow task list
        oList = clientContext.get_web().get_lists().getByTitle('Workflow Tasks');
        itemCreateInfo = new SP.ListItemCreationInformation();
        this.oListItem = oList.addItem(itemCreateInfo);
        //oListItem.set_item('ContentType', 'Mark As Read');
        oListItem.set_item('Title', 'Read Notification: Javascript');
        //oListItem.set_item('Body', 'Hello World!');
        oListItem.update();
        //clientContext.load(oListItem);

        //OnSuccess....
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    };

};

function onQuerySucceeded(sender, args) {
    console.log('Query Succeeded');
    console.log(currentUser.get_loginName());
    for (i in items) {
                console.log(items[i].id);
    }
}

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

If I do the "//get workflow task list" where it is it creates the task.  I'd prefer it create the task in the onQuerySucceeded function.  When I put the code there it fails.  What am I doing wrong?

I'm like to get all the arguments and on success create the task using those arguments in the task.

Thanks for the help in advance.


David Jenkins


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>