upload a file to sharepoint document library programmatically using jsom and set the property in one step( to get version 1)

Dears,

I have worked on document library uploading files with setting some custom fields using JSOM and every thing works fine

my problm is the version  built in field is appear to be 2 once im done and this is not acceptable to the client 

i know it comes 2 cause of uploading and setting the fields value 

MY question is there any way to upload a file and set the property fields in one step to have Ver.1 once i uploaded the file from my custom work 

March 29th, 2015 9:56am

Hi,

Yes, after uploading a file, updating fields in library, the version number will get increased.

As a workaround, since the version number can be changed using Client Object Model, I suggest you create an extra column for saving a fake current version number. Then when uploading files using JavaScript Client Object Model, you can update that extra column accordingly.

From user side, they will only see the fake column instead of the built-in Version column.

Thanks 

Patrick Liang

Free Windows Admin Tool Kit Click here and download it now
March 30th, 2015 11:22am

Hi  Patrick,

thank you, but this way is not acceptable for the client cause we display the version history to him and he will see # of versions different from the one he see in the view list

I found a solution for it  like below using rest with bNewDocumentUpdate parameter

 $scope.updateMetadataNoVersion=function(fileUrl) {
    var fld=$scope.SelectedFolder.replace(_spPageContextInfo.siteAbsoluteUrl, "");


       var restSource ="";
        if(fld.replace("lists/DepartmentDocuments","")=="")
       restSource = currentWeb.get_url() + "/_api/web/lists/getbytitle('DepartmentDocuments')/rootfolder/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem";
  
else
       restSource =  currentWeb.get_url() + "/_api/web/getfolderbyserverrelativeurl('"+fld+"')/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem";
  
        var dfd = $.Deferred();
      
        $.ajax(
        {
            'url': restSource,
            'method': 'POST',
             'data': JSON.stringify({
                'formValues': [
                    {
                    '__metadata': { 'type': 'SP.ListItemFormUpdateValue' },
                    'FieldName': 'ShareWith',
                    'FieldValue': '24'
                }

                ],
                'bNewDocumentUpdate': true,
                'checkInComment': ''
            }),
            'headers': {
                'accept': 'application/json;odata=verbose',
                'content-type': 'application/json;odata=verbose',
                'X-RequestDigest': $('#__REQUESTDIGEST').val()
            },
            'success': function (data) {
                var d = data;
                dfd.resolve(d);
            },
            'error': function (err) {
                dfd.reject(err);
                console.log(err);
            }
        }
       );

 

        return dfd.promise;
    }

my problem now with user field it does not accept any value but it goes to the success function in the request

any suggestion please

March 31st, 2015 8:33am

Hi,

Seems there are already replies in your another similar thread about this issue:

https://social.technet.microsoft.com/Forums/en-US/5e67dc3d-c808-49ee-9aab-383a5cea5bce/sharepoint-angulr-rest-api-update-file-item-userd-field-property?forum=sharepointdevelopment

Please check whether they are helpful to you.

Thanks 

Patrick Liang

Free Windows Admin Tool Kit Click here and download it now
April 3rd, 2015 2:00am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics