accounts_opportunities relationship
Closed this issue · 5 comments
I am trying to create a new opportunity and associate the opportunity to an existing account, but I am not able to see the way to do it. For example I am trying with this test method where I use my own Configuration object where I store the credentials to access SugarCRM
public static void createTestAssociation(Configuration configuration) throws Exception {
String sugarcrmHost = configuration.getSugarcrmHost();
String urlpath = getUrlPath(sugarcrmHost);
String username = configuration.getSugarcrmUsername();
String password = configuration.getSugarcrmPassword();
SugarRestClient client = new SugarRestClient(urlpath, username, password);
String accountId = "5c68e9c7-d66e-a679-9da4-577e5cca64c3";
String opportunityId = "ca9ebdea-85d5-7fca-e078-58ee55950447";
AccountsOpportunities insertAccOpp = new AccountsOpportunities();
insertAccOpp.setAccountId(accountId);
insertAccOpp.setOpportunityId(opportunityId);
SugarRestRequest request = new SugarRestRequest("AccountsOpportunities", RequestType.Create);
request.setParameter(insertAccOpp);
//request.setModuleType(AccountsOpportunities.class);
// Select fields.
List<String> selectFields = new ArrayList<String>();
selectFields.add(NameOf.AccountsOpportunities.AccountId);
selectFields.add(NameOf.AccountsOpportunities.OpportunityId);
request.getOptions().setSelectFields(selectFields);
SugarRestResponse accOppResponse = client.execute(request);
String insertId = (accOppResponse.getData() == null) ? StringUtils.EMPTY : accOppResponse.getData().toString();
}
Could you please tell me what is wrong?
Many thanks.
I'm not very familiar with SuiteCRM API (yet), but I think relationships need to be set via the API command set_relationship. However, this client does not implement set_relationship yet. In my fork at https://github.com/Frankst2/SugarOnRest I'm currently working on a way so that at least creating an entity will also set these relationships automatically. But this is still work in progress and totally not ready for production :) (I plan to contribute the code back to this repository when this is working).
Thank you Frankst2! It is what I supposed. I am trying to do the direct call to the REST API using set_relationship, but as I am not very familiar with SugarCRM REST API is taking me longer that I wanted.
@mattkol I was testing out this library and have the same need as jgroiz. I am able to add an opportunity but not associate it to the account. Has this been resolved? Is there a workaround to it?
Unfortunately I probably won't be able to contribute the code back. Feel free to check out my code at https://github.com/Frankst2/SugarOnRest and use it/merge it. I wrote this code as part of a project and I'm no longer working on that project.