Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Update Module

mattkol edited this page Jan 21, 2017 · 2 revisions

Basic Usage

This sample usage shows how to update "Bugs" module entity data. For more request options make changes to the [Options parameter](Request Options).

This implements the set_entry SugarCRM REST API method.

package com.sugaronrest.tests;

import com.sugaronrest.*;
import com.sugaronrest.modules.Bugs;

import java.util.List;
import java.util.Map;

String url = "http://demo.suiteondemand.com/service/v4_1/rest.php";
String username = "will";
String password = "will";

SugarRestClient client = new SugarRestClient(url, username, password);
SugarRestRequest request = new SugarRestRequest(Bugs.class, RequestType.ReadById);

String bugId = "2e1cbd26-a8ed-755b-23f1-5883cc4de3ae";
request.setParameter(bugId);

// Read Bugs data
SugarRestResponse bugReadResponse = client.execute(request);
Bugs bugToUpdate = (Bugs)bugReadResponse.getData();

request = new SugarRestRequest(Bugs.class, RequestType.Update);

// Update description
bugToUpdate.setDescription("Now 7th floor printer");
request.setParameter(bugToUpdate);

// Select fields.
List<String> selectFields = new ArrayList<String>();
selectFields.add(NameOf.Bugs.Name);
selectFields.add(NameOf.Bugs.Description);
selectFields.add(NameOf.Bugs.Status);

request.getOptions().setSelectFields(selectFields);

SugarRestResponse response = client.execute(request);

Response (getData())

String updatedBugId = (String)response.getData();

Response (getJData())

"2e1cbd26-a8ed-755b-23f1-5883cc4de3ae"

Response (getJsonRawRequest())

{
  "method": "set_entry",
  "input_type": "json",
  "response_type": "json",
  "rest_data": {
    "session": "r46g62lphhehudmktsv8es9pc7",
    "module_name": "Bugs",
    "name_value_list": {
      "name": {
        "name": "name",
        "value": "System crashed while running count query"
      },
      "description": {
        "name": "description",
        "value": "Now 7th floor printer"
      },
      "id": {
        "name": "id",
        "value": "2e1cbd26-a8ed-755b-23f1-5883cc4de3ae"
      },
      "status": {
        "name": "status",
        "value": "New"
      }
    }
  }
}

Response (JsonRawResponse)

{
  "id": "2e1cbd26-a8ed-755b-23f1-5883cc4de3ae",
  "entry_list": {
    "name": {
      "name": "name",
      "value": "System crashed while running count query"
    },
    "description": {
      "name": "description",
      "value": "Now 7th floor printer"
    },
    "id": {
      "name": "id",
      "value": "2e1cbd26-a8ed-755b-23f1-5883cc4de3ae"
    },
    "status": {
      "name": "status",
      "value": "New"
    }
  }
}