2

In a sharepoint 2013 Blog site I am posting a post on behalf of few senior members of our organization. As usual it shows my name in posted by field. Is there a way to change that programatically change the AuthorId.

I had tried the following code

<script src="/apps/test/Style%20Library/css%20files/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="/apps/test/Style%20Library/css%20files/jquery.SPServices-2013.02a.js" type="text/javascript"></script>

<script type="text/javascript">
var siteUrl = '/apps/test/blog';

function updateListItem() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Posts');

    this.oListItem = oList.getItemById(5);

    oListItem.set_item('AuthorId', '22');

    oListItem.update();

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

function onQuerySucceeded() {

    alert('Item updated!');
}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>

When I execute the above code it says,

Request failed. Column 'AuthorId' does not exist. It may have been deleted by another user. /apps/opus/blog/Lists/Posts undefined

But When I read the same list using similar JS code I am able see AuthorId. Please suggest a way to update/change AuthorId for a post.

1

Blogs list contains field Author(Title: Created By) and since it is a user field type, it value is represented by SP.FieldUserValue object via JSOM.

Solution

Replace the line:

oListItem.set_item('AuthorId', '22');

with

oListItem.set_item('Author', 22); //value corresponds to User Id 
  • couldn't get this to work in foundation – Batman Oct 7 '14 at 20:05
  • I would recommend to create a separate question for this request – Vadim Gremyachev Oct 7 '14 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.