0

I just want to update a specific field in a list. How do i do that. I'm developing an android application that updates certain values to the list that I have created in Share point. I'm able to insert a row in the list but i'm not able to update a specific row. Below is my android code.

public void updateListItems()
{

    try {
        CookieManager cookieManager = (CookieManager)CookieHandler.getDefault();
        cookies = cookieManager.getCookieStore().getCookies();
        String body ="{ '__metadata': { 'type': 'SP.Data.ClockTrackListItem' },'UId' : '171028', 'CurrentDate' : '2016-08-05T04:00:00Z' ," +
                "'TimeIn' : '10:12:12' , 'TimeOut': '22:12:12' ,'TotalTime': '10:12:12' ,'Title': 'Dharma'}";
       Uri uri = Uri.parse("http://cloudapps.cctspl.com/sites/ClockInClockOut/_api/Web/lists(guid'"+retrieveList()+"')/items");
       // Uri uri = Uri.parse("http://cloudapps.cctspl.com/sites/ClockInClockOut/_api/Web/lists/GetByTitle('ClockTrack')/GetItemById(5)");
        URL url = new URL(uri.toString());
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setDoInput (true);
        urlConnection.setDoOutput(true);
        urlConnection.setRequestMethod("POST");
        urlConnection.setRequestProperty("Accept", "application/json;odata=verbose");
        urlConnection.setRequestProperty("content-type", "application/json;odata=verbose");
        urlConnection.setRequestProperty("X-RequestDigest",getRequestDigest());
        urlConnection.setRequestProperty("X-HTTP-Method-Override","MERGE");
        urlConnection.setRequestProperty("If-Match","12");

        urlConnection.connect();
        OutputStream os = urlConnection.getOutputStream();
        os.write(body.getBytes());
        os.flush();
        os.close();
        int resCode = urlConnection.getResponseCode();
        Log.d("Response Code :" ," "+resCode);
        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader reader =new BufferedReader(new InputStreamReader((inputStream)));
        StringBuffer buffer = new StringBuffer();
        String line;
        while((line = reader.readLine()) != null)
        {
            buffer.append(line + "\n");
        }
        String restResult = buffer.toString();
        Log.d("----Buffer String-----:" , restResult);
        JSONObject jobj = new JSONObject(restResult).getJSONObject("d");
   }  catch (Exception e)
    {
        Log.v("Retrieve List", e.toString());
        e.printStackTrace();
    }
}

Can anyone guide me with this. tell me where I have committed a mistake.

1 Answer 1

0

You need to update the url to contain the item id example: http://site url/_api/web/lists/GetByTitle(‘Test')/items(item id)

Reference : Working with lists and list items with REST

2
  • Uid is a field in my list. It's not the item Id.
    – Dharma Raj
    Aug 8, 2016 at 7:51
  • Ok, please see my updated answer
    – oftedal
    Aug 8, 2016 at 8:23

Your Answer

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

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