TransWikia.com

Check In file with Javascript and REST

SharePoint Asked by Anders on December 19, 2020

I am trying to check in a file from my sharepoint-hosted app with jsom and rest, but it wont work

my code look like this:

function checkInFile() {

    var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    currentContext = new SP.ClientContext.get_current();
    var hostContext = new SP.AppContextSite(currentContext, hostUrl);
    hostweb = hostContext.get_web();
    currentContext.load(hostweb);

    currentContext.executeAsync(function(){

        url: appWebUrl + "/_api/SP.AppContextSite(@target)/web/getfilebyserverrelativeurl('/style library/popup.js')/checkin(comment='Check-in comment.',checkintype=0)?@target="+ hostWebUrl + "",
        method; "POST", 
        success; successHandler,
        error; errorHandler
    });

         function successHandler() {
              $('#message').append('<br /> <div>File sucessfully checked-in</div>')
           }
           function errorHandler(sender, args) {
             $('#message').append('<br /><div>Error: Status file not check-in</div>');
           }
 }

One Answer

You can access the host web to check in the file using REST with the cross domain javascript library as mentioned in this article link. You need to execute the query on the RequestExecutor.

Answered by Vipul Kelkar on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP