I'm trying to add targets to target lists in Sugar via REST service calls. I'm getting a positive response from Sugar but records are not added. The service method I'm using is *set_relationship*:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"ProspectLists",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospects",
"name_value_list":[],
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
I also tried it the other way around:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"Prospects",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospect_lists",
"name_value_list":[],
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
In both cases I get a promising response:
{"created":1,"failed":0,"deleted":0}
...but when I check the target list I can't find any added targets. I also checked the database but there is no trace either.
My Sugar Version is 6.5.16 CE and I'm using the SuiteCRM 7.0.1 extension but I don't think this makes a difference here.
Any hint is highly appreciated. Thanks!
I finally figured it out. It seems like set_relationship is very picky about the parameter order. The parameter naming doesn't even mean a thing. This worked in the end for me:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"Prospects",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospect_lists",
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
Working Python code (API v4.1):
import sugarcrm
import json
import requests
crm_session = sugarcrm.Session(CRM_HOST, CRM_USER, CRM_PASS)
payload = {
"method": "set_relationship",
"input_type": "JSON",
"response_type": "JSON",
"rest_data": json.dumps({
"session": crm_session.session_id,
"module_name": "Prospects",
# ID of the record you're creating relationship FROM
# In my case it is a record from module "Prospects"
"module_id": "cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name": "events_prospects",
# ID of the record you're creating relationship FOR
# In my case it is a record from module "events"
"related_ids": ["534f894a-4265-143d-c94b-52be908685b1"],
"name_value_list": [],
"delete": 0
})
}
result = requests.post(CRM_HOST, data=payload)
#Till is right, be careful with the order of "rest_data" parameters. In my case placing name_value_list before related_ids has been producing positive results with no actual relationship created.
p.s. I'm using this library: https://pypi.python.org/pypi/sugarcrm/0.1
Related
I wanna add properties such as "created_by" and "created_at" to each and every object in pretty much every collection in firestore.
The only approaches I can think of so far are.
Add them in the client-side code but verify them on the server side using Security Rules.
or better:
Add them automatically on the server side using Cloud Firestore function triggers onCreate and onWrite events.
However, both approaches sounds like workarounds for a very common task for which I would expect an out-of-the-box solution.
Does anybody know any out-of-the-box approach for that?
There's no built-in solution for this. Cloud Functions sounds redundant as security rules can ensure the values are correct:
allow create: if request.resource.data.created_at == request.time && request.data.created_by == request.auth.uid;
You can use serverTimestamp() for created_at when adding the document so the rules will return true as mentioned in the documentation.
For Firestore write operations that include server-side timestamps, this time (request.time) will be equal to the server timestamp.
You can use withConverter() so you don't have to repeat the same code to add those common fields. Instead, declare the converter once and use it for any read/write operations as required:
const addDefaultFields = {
toFirestore: (docData: any) => {
// TODO: Add created_at and other fields
return {
created_at: serverTimestamp(),
...docData,
}
},
fromFirestore: (snapshot: any, options: any) => {
const data = snapshot.data(options)
return {
id: snapshot.id,
...data,
}
},
}
const docRef = doc(db, 'col', 'alovelace').withConverter(addDefaultFields)
I am trying to move some old code that used the older google-api-client gem to the Idiomatic Ruby client google-cloud-ruby.
The process is a simple query job that saves it's results to another table. In the older gem, I used a config like this:
config= {
"jobReference": {
"projectId": GOOGLE_PROJECT,
'location'=> 'europe-west2'
},
'configuration'=> {
'query'=> {
'allowLargeResults' => true,
'createDisposition' => 'CREATE_IF_NEEDED',
'writeDisposition' => 'WRITE_TRUNCATE',
'query' => sql,
'destinationTable'=> {
'projectId'=> GOOGLE_PROJECT,
'datasetId'=> 'my_dataset',
'tableId'=> table,
'location'=> 'europe-west2'
}
}
},
}
Following the docs for the newer library, I am running this as a basic test (the sql is defined elsewhere)
bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset('my_dataset')
puts(dataset.location)
puts("1")
job = bigquery.query_job(sql, table: dataset.table(table), write: 'truncate', create: 'needed')
puts("2")
job.wait_until_done!
puts("3")
job.done?
This gets as far as the puts 2, failing on job.wait_until_done! with the error Google::Cloud::NotFoundError: notFound: Not found: Job my_project:job_hApg5h0NQQb4Xbv7Sr3zzIXm5RWF
If I 'puts' the job.job_id I see the same ID as it's saying it can't find. I've tried running this in datasets in multi-region and single location and still the same error. Ultimately, I need this to run on the 'europe-west2' region only.
Can anyone help and/or point me to a working example? Thanks in advance!
As suggested by #Tlaquetzal, you can replace your SQL query to a simple SELECT 1 as below sample query and see the results.
sql = "SELECT 1 FROM `project.dataset.table`"
Wrapping another javascript library to use with Ember bindings, etc, seems like an ordinary thing to do, but I haven't found much discussion of it.
I want to filter an ember record array using distance and travel time from the Google Maps Distance Matrix
service. I'm just not sure where in the application to encapsulate Google's javascript. Note: this is not a question about embedding a google map, it's about getting data into ember that doesn't come from a rest/json or fixtures as in all the tutorials and examples I've found.
Would people typically do this in the controller or create new models/adapters to get benefits from store caching? Or is there another way?
update: in case that's too vague, consider this: 20 records (with a google map component etc) listed by an array controller, a text field where the user types in a home address, a couple of other inputs where they set a maximum time or distance, and a search button which filters the listed records by comparing the user requirements with the result of querying the distance matrix for the home address to the 20 records' addresses, only showing the ones close enough to their home.
Use of the service in an application that doesn't display a Google map is prohibited.
So,the question is really about integrating a Google map to an Ember app.
Without any doubt you'll have to add the Google JS like in any other HTML project with:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MYSECRETKEY"></script>
So, the API is in global space and you just use it whenever you need it. Mostly all that will happen in your views, so you could wrap everything in a component. (I'm assuming that all relevant data has been passed from the controller to the view, it all depends on the design of your app.)
The following works, but it seems like it should be in the model/store/adapter layer.
App.DistanceController = Ember.Controller.extend
origin: (->
data = #get('data')
data.origin if data
).property('data')
destinationDistances: (->
data = #get('data')
data.distances if data
).property('data')
data: ((key, value)->
if arguments.length > 1
value
else
_this = this
value = null
service = new google.maps.DistanceMatrixService()
service.getDistanceMatrix(
origins: ["London, England"],
destinations: [
"Bristol, England",
"Edinburgh, Scotland",
"Leeds, England",
"Liverpool, England",
"Manchester, England",
"Newcastle, England",
"Nottingham, England",
"York, England"
],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false
, (response, status) ->
if (status == google.maps.DistanceMatrixStatus.OK)
distances = []
for destination, n in response.destinationAddresses
distances.push {
destination: destination
distance: response.rows[0].elements[n].distance.text
}
_this.set('data', {
origin: response.originAddresses[0]
distances: distances
})
)
value
).property()
kudos #rlivsey https://stackoverflow.com/a/20623551/395180
I am wondering how I can use ember-data working with a Spring/Hibernate Java backend. I would usually use Jackson to return JSON but that does not appear support the specifications required by jsonapi.org.
Currently beans are returned in a hierarchical nature like this.
{
"id" : 1,
"name" : "Bill",
"surname" : "Smith",
"address" : {
"id" : 23,
"number" : 21,
"street" : "Vincent st",
"state" : {
"id" : 44,
"name" : "Victoria"
"abbreviation" : "VIC"
}
"postcode" : 9000
}
}
I am not stuck to this structure and it can be modified to suite jsonapi, however, I can't find any jackson plugin that will serialize/deserialize my objects to the jsonapi specification.
What are my options here? I know that I am able to write my own serializer/deserializer for ember-data but that would be a huge pain, surely there are other people using ember with a java backend.
This looks familiar to an issue I had parsing json with DataFX (using javaFX), json was also generated by Spring...
I ended up returning a Page which wraps your Person and creates some json that is parseable.
Just my 2cts... I added the following requestmapping to my PersonController:
#RequestMapping(value="/persons", method=RequestMethod.GET, headers="Accept=application/json, application/xml")
public #ResponseBody Page<Person> getPersons(
#RequestParam(value="page",required=false,defaultValue="0") String page,
#RequestParam(value="size",required=false,defaultValue="20") String size,
#RequestParam(value="orderby",required=false,defaultValue="name") String orderby){
PersonRepository repository = context.getBean(PersonRepository.class);
final PageRequest pr = new PageRequest( Integer.parseInt(page), Integer.parseInt(size), Direction.ASC, orderby);
Page<Person> persons = (Page<Person>) repository.findAll(pr);
return persons;
}
I'm new to ember and still in the design stages with php as a backend, but I believe I have the same problem and found what looks like a fix. You're right that messing with jackson would be a difficult approach. It seems like it's much easier to make the change on the ember side. This guide (http://lab.empirio.no/emberjs-say-hello-to-apigility.html) discusses creating our own serializer in js based on ember data's ActiveModelSerializer and then modify the RestAdapter. The example is discussing building the standard ToDo app that I'm sure you've seen used as an example already.
The problem is the backend uses this format:
{"name":"Testing","is_completed":false}
While ember uses:
{"todo":{"name":"Testing","is_completed":false}}
Here's some same code:
App.ApplicationSerializer = DS.ActiveModelSerializer.extend({
primaryKey: 'todos_id',
extract: function(store, type, payload, id, requestType) {
this.extractMeta(store, type, payload);
if(payload._embedded)
payload = payload._embedded;
if(requestType == 'updateRecord' || requestType == 'createRecord'){
var data = {};
data[type.typeKey] = payload;
payload = data;
}
var specificExtract = "extract" + requestType.charAt(0).toUpperCase() + requestType.substr(1);
return this[specificExtract](store, type, payload, id, requestType);
}
});
... "we manipulate the payload by extending (copying from the RESTAdapter).
the createRecord-function changes the behavior on the adapter like this: "
createRecord: function(store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record, { includeId: true });
return this.ajax(this.buildURL(type.typeKey), "POST", { data: data[type.typeKey] });
},
I'm sure I'm missing a lot here and probably missing some steps since I haven't even tried to build the app yet, but this was a problem I knew I needed to address before I committed to ember and this seems like a viable solution. I hope its a step in the right direction for you anyway.
edit: I know you didn't want to change the format for the sake of sticking to the standard, but there really isn't a standard for JSON APIs and content types yet, not one that's accepted anyway. This guide uses HAL + JSON which doesn't look any different from what I see at jsonapi.org if that's what you were talking about. Regardless, everyone seems to be having this issue regardless of backend language or frameworks.I think the ember team recognizes this and are trying to be flexible. Also, since ember-data is still in beta, I'd be more apt to make the changes there instead of writing the java side to support a changing library. Who knows? Maybe ember-data will have better support for different backends before its 1.0 release, although I haven't heard any mention of it on the roadmap.
at the moment, when ember is asking for child data through the rest adapater, it makes a GET request with the following options:
http://localhost/orders?ids%5B%5D=0x0000000000000386&ids%5B%5D=0x00000000000003a4&ids%5B%5D=0x00000000000003cf&ids%5B%5D=0x0000000000000631&ids%5B%5D=0x0000000000000639
which equates to parameters of
ids[]:0x0000000000000386
ids[]:0x00000000000003a4
ids[]:0x00000000000003cf
ids[]:0x0000000000000631
ids[]:0x0000000000000639
I was wondering if there was a way of changing that to be either
id1:0x0000000000000386
id2:0x00000000000003a4
id3:0x00000000000003cf
id4:0x0000000000000631
id5:0x0000000000000639
or
{ids: [{"id":"0x0000000000000386"},
{"id":"0x00000000000003a4"},
{"id":"0x00000000000003cf},"
{"id":"0x0000000000000631"},
{"id":"0x0000000000000639"}
]}
I have solved this by using the "links" option in the data.
Within the json returned at the higher level , include the links
{customers : [
{name": "foobar inc",
"links": {"orders:/customers/181/orders"}
}]
}
so now when ember tries to get the orders of a customer, it will make a json request to the url specified in the links
this works really well for me. It also has the advantage of not having to load all children in as either ids[] or sideloading.