Need to update values in wix database after same values are updated in an google spreadsheet.
Wrote PUT function to update the data but keeps returning with a 500 error. Any suggestions?
export function put_updaterecords (request) {
return request.body.json()
.then(body => {
let recordUpdate = {
"_id": body.ID,
"title": body.Title,
"firstName": body.FirstName,
"lastName": body.LastName,
"color": body.Color,
"number": body.Number
};
return wixData.insert('GoogleSheetstoWixDatabase', recordUpdate)
.then(result => ok({body: JSON.stringify(result)}))
.catch(err => response({status: 500, body: err}));
})
}
check your permissions on the dataset, make sure it's set to 'any' for the view/create field. I had this same issue.
What this code doesn't do (I'm assuming you got it from wixshow like me) is it doesn't allow data-in-place updates, meaning any time there's a change to a field, it adds new rows instead of updating existing ones. If anyone can shed light on using wixData.update in place of .insert that would be helpful...
Simple solution in the end. Had overlooked the settings of the database. Changed settings to update the database to allow and it worked.
Related
I have data I would like to use in multiple components and manipulate. For that reason I decided to start using store, but I don't know at what stage I'm supposed to do request to the server and set store data.
The question is probably asked before but I could not find it
Your question is not clearly but if you want to centralize your logic. Your store file looks like that:
state:{
user:{
id: "",
name: "",
...
..
.
}
}
getters:{
get_user: state => state.user,
get_userID: state => state.user.id,
...
}
mutations:{
SET_USER(state, payload){
state.user = payload
},
SET_USER_ID(state, payload){
state.user.id = payload
}
...
}
actions:{
add_user({ commit }, userData){
// you can make some http request here if you have
commit("SET_USER", userData)
}
}
Basically, above code is showing you a logic. If you want to get some data which is in state, you should had a getters. If you want to change some data which is in state, you should use mutations to make this. If you want to make some functionality like post user detail to server, fetching data from server something like this you should use actions and even you can make those changes in your actions, don't. Because actions work async, mutations not.
I hope this is answer what you looking for.
I'm trying to query tasks by ObjectID to get their most recent snapshots. I'm trying the API out, and am not getting the expected results that I was hoping for after reading the docs. I don't get a results field in the response object. Here's my code:
_loadTaskSnapshot: function() {
let snapshot = Ext.create('Rally.data.lookback.SnapshotStore', {
context: {
workspace: '/workspace/2290039850'
},
"find": {
"ObjectID": 34858774310,
"_ValidFrom": {
"$gte": "2016",
"$lt": "2017"
}
},
"fields": ["Name", "Estimate", "ToDo", "TimeSpent"],
});
return snapshot.load();
}
This is the store with 18 snapshots for the specified task. The first snapshot is opened. You can see there is no results field where I could find the Name, Estimate, ToDo, and TimeSpent:
Alejandro, you are asking for the changes in the fields, not the values of the fields. This is a common misconception with the lookback api. There is a special way to get the current values shown in the help pages available inside Agile Central.
Any information returned is actually held within the object underneath 'raw' and 'data'. Each of those may not contain any values if there has been no 'changes' to those fields at the time the snapshot was taken.
Is it possible to access custom fields for orders, products, customers via WooCommerce REST API? If not natively, then what plugins or workarounds or hacks are out there that work? Thanks!
Answering my own question:
It is possible using the following: (using v3 legacy API)
To send custom fields back to the server:
(For Orders)
{
"order_meta": {
"key": "value"
}
}
To retrieve custom fields from server use this filter with your end point:
http://www.example.com/wc-api/v3/orders?filter[meta]=true
This works for Products as well.
As mentioned in the comment after WooCommerce creates an order via the API it will fire woocommerce_api_create_order hook, you can make use of it.
Add the following code to your theme's functions.php file
add_action( 'woocommerce_api_create_order', 'my_woocommerce_api_create_order', 10, 2);
function my_woocommerce_api_create_order( $order_id, $data ) {
// $data contains the data was posted, add code to extract the required
// fields and process it as required
}
Similarly look at the code in plugins/woocommerce/includes/api/*.php files, find the suitable action or filter hook for the end point and use it.
SIMPLE SOLUTION THAT WORKED FOR ME (using REST API REQUEST):
URL: https:///wp-json/wc/v3/orders/1234
METHOD: PUT
BODY:
{
"status": "completed",
"meta_data": [{
"key": "is_web_server_handled",
"value": "1"
}]
}
I've implemented the dgrid. It's really neat. However when I click on the row header to sort, all but one row disappears. I'm going nuts trying to figure out why....
Let's give this a go.
DGrid, it's a dojo based data grid, see http://dojofoundation.org/packages/dgrid/
When using this with Javascript and HTML and connecting to an Observable MemStore, the grid populates, with several rows quite happily displaying data. The columns are sortable, that is you can click on the the row/column heading. However - and here's the problem - when clicking on these row/column headers to sort the row's, all but one row disappears.
Using a Memory (dojo/store/Memory) a the dGrids data store work fine - ie the rows sort successfully. However when using the Observable (dojo/store/Observable) as a data store the sort causes the rows to collapse. Please see below examples.
Sort working great with Memory:
function populateGrid(Memory, message) {
var featureOne = {
"id": message[0].attributes["id"],
"Col2": message[0].attributes["Col2"],
"Col3": message[0].attributes["Col3"]
}
var featureTwo = {
"id": message[1].attributes["id"],
"Col2": message[1].attributes["Col2"],
"Col3": message[1].attributes["Col3"]
}
var data = [feature1, feature2];
var memStore = new Memory({ data: data });
window.queryRecordsGrid.set("store", memStore);
}
The error occurs when using Observable:
var memStore;
function populateGrid(Memory, message) {
var feature = {
"id": message[0].attributes["id"],
"Col2": message[0].attributes["Col2"],
"Col3": message[0].attributes["Col3"]
}
var data = [feature];
if (!window.memStore) {
window.memStore = new Observable(new Memory({ data: data }));
window.grid.set("store", window.memStore);
} else {
window.grid.store.notify(feature, feature.id);
}
}
This might or might not be your issue, but currently the items in your store don't have unique identifiers - or if they do, they're not being picked up by the store correctly. dojo/store/Memory defaults to assuming that store items each have a unique id. If you have another field which provides unique identifiers, you can make Memory aware of this by setting idProperty, e.g.:
new Observable(new Memory({ idProperty: "Col1", data: data }));
You also seem to be assuming that feature.id exists when you call notify but as far as I can tell from your code, it doesn't exist.
When attepming to use a Rally.data.BulkRecordUpdater, I ran into a few problems. First of all, the documentation is incorrect. The example provided:
Rally.data.BulkRecordUpdater({
records: [record1, record2],
propertiesToUpdate: {
Parent: '/hierarchicalrequirement/123.js'
},
success: function(readOnlyRecords){
//all updates finished, except for given read only records
},
scope: this
});
should be:
Rally.data.BulkRecordUpdater.updateRecords({
records: [record1, record2],
propertiesToUpdate: {
Parent: '/hierarchicalrequirement/123.js'
},
success: function(readOnlyRecords){
//all updates finished, except for given read only records
},
scope: this
});
Secondly, when trying to use this method to update records I keep getting an error for being unable to call the method 'get' - I am assuming that this is because the records I am providing are not in the correct format. I am simply calling this on records I pull from a wsapi query. I have tried putting the object inside of another object:
{data: record}
but it still does not seem to help. Any ideas would be greatly appreciated!
Thanks for pointing out the doc issue. I'm filing a defect to fix this.
The records should be instances of Rally.domain.WsapiModel. If you are using Rally.data.WsapiDataStore to retrieve them then you should be all set. Are you doing something different?
For what it's worth, we're also currently working on another, better way to do batch updates of records. Look for it in a future SDK!
See this example if it helps
_justFunction: function(_childObj) {
records = ["abc", "xyz"];
var store = Ext.create('Rally.data.custom.Store', {
data: records,
listeners: {
load: that._updateAll,
scope: that
},
});
},
_updateAll: function(store,data) {
Rally.data.BulkRecordUpdater.updateRecords({
records: data,
propertiesToUpdate: {
Parent: _newParent.get("_ref")
},
success: function(readOnlyRecords){
//all updates finished, except for given read only records
},
scope: that
});
},