I have a table customer with fields id,name,nickname.. I'm using grocery crud for add/edit. The field nickname should be automatically created based upon the name field. Can anyone suggest what can be done to accomplish this
You can accomplish this by using the callback_before_insert function of grocerycrud.
Here is a link to the description: callback_before_insert
Before you render your output add this:
$crud->callback_before_insert(array($this,'create_nickname_callback'));
Add the callback method:
function create_nickname_callback($post_array) {
$post_array['nickname'] = your_nickname_value;
return $post_array;
}
Related
Within Customization -> List, Records & Fields -> Custom Records I have a table with id: customrecord_{name} with the type "customrecordtype". I have multiple fields in that record
How can I use the load function to get all the data for this table/record? (For all the fields)
const data= record.load({
type: 'customrecord_{name}',
isDynamic: false
... //get all fields
});
I tried to look at the help center but am a bit lost on how to accomplish this.
As far as I know load won't do it. After loading a custom record with load, you can check all the fields of this custom record by calling data.getFields() method. This will return a list of field ids (including custom ones) that you can fetch by calling data.getValue such as data.getValue({'fieldId':'isinactive'}) // a regular field or data.getValue({'fieldId':'custrecord_routeproduce_highpriority'}) // a custom field
loading a custom record, checking its fields, fetching value of a custom field
I'm working on GraphQL API, and I want to filter my data "Products" by sellerId knowing that a product can be sold by several sellers, which means the sellers' field is an array.
Here is the query:
query GetProducts($filterObject:ProductWhereInput!){
products(where:$filterObject){
id
name
description
sku
price
sellers(where:$filterObject.sellers){
id
firstname
lastname
}
images{
url
fileName
}
}
}
Filter variable is defined like that
{
"filter":{
"sellerId":"ckzia0llkfngz0d09mrppd7kh"
}
}
and when I execute this query I get the error
"message": "unknown field 'filterObject.sellers' in variables"
I'm not sure if that's the correct method to apply the filter, it worked for me when I use it for single-value fields, but not with arrays.
If someone could help me, I'll be thankful.
Here you defined $filterObject as a query variable
query GetProducts($filterObject:ProductWhereInput!)
But the way this line is written, it "uses" a variable that is not defined:
sellers(where:$filterObject.sellers)
It's looking for a variable named: "$filterObject.sellers", not a property "sellers" of $filterObject.
Possible solution 1 - server side:
You can change the sellers field definition to use the whole $filterObject and then the resolver function on the server can extract the field it needs.
sellers(where:$filterObject)
This solution makes sense if you have control over the server side.
Possible solution 2 - client side:
If you cannot change the code on the server side, you can define a separate variable and use it instead:
query GetProducts($filterObject:ProductWhereInput!, $filterSellersObject:ProductSellersWhereInput!){
//...
sellers(where:$filterSellersObject){
//...
(assuming ProductSellersWhereInput is a defined type)
I have a base in airtable and now I need to up columns(fields) programmatically.
For example sql has a query for this operation
ALTER TABLE Employees
ADD EmployeeID numeric NOT NULL IDENTITY (1, 1)
Is there a API for Airtable to do such operations?
Airtable offers an API to use, but not for adding columns. There is a Node.js package and several other programing libraries available on Github.
They have official Doc's as well https://airtable.com/api. With out getting creative and hacking something together, it is not possible to modify a table’s schema via the API. So you cannot do actions like add columns or modify the values in an existing table.
var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('app$$%&#*(#');
base('Employees').update('EmployeeID', {
"EmployeeID": "Number"
}, function(err, record) {
if (err) { console.error(err); return; }
console.log(record.get('EmployeeID'));
});
Here is a quick snippet of an update function to update a record.
you can't update dynamically an Airtable table. You can update only the existent field values. The response from Nick C is the syntax to PATCH a record.
I am trying to add documents, according to elastic search documents, we can add document, even if we dont provide id... See Here
I am trying to add a document even if it doesnt have any ID. in elastic search, how can i do that?
My current code looks like this
var params = _.defaults({}, {
index: index,
type: type, //'customer'
id: data.id || null,
body: data
})
debug(params)
return this.client.create(params);
The above code gives this error
{
"error": "Unable to build a path with those params. Supply at least index, type, id"
}
Any hint would help, thanks
With the create call you MUST provide an id.
If you are not sure if an ID will be present in your data , then you can use the client.index() function instead. using that function, ES will auto-generate an ID if none is provided.
I have made a JS logger application in Sails.js and everything looks great.
Now, I'm on my way to scale the application: I need to use several tables for the same model (e.g. a table for session1 sesson2 etc based on id).
Let's say that for model "Pageview", I'll be using different tables, like "Pageview1", "Pageview2", and so on.
How could I define dynamically the tableName of that model, so I can change it on every request according to a param or attribute.
So far, I have tried this way
var tableId = 2;
Pageview.tableName = "pageview" + tableId;
Pageview.create(values, function...);
That code does not break the application, or throw any errors, but the record was saved on the default table, instead of the one I wanted.
I dont think it is possible to do so , but when i read this
I think you can use the custom format to dynamically define table names.
If you are inserting a row into a table with an auto increment primary key, you can retrieve the insert id like this:
connection.query('INSERT INTO posts SET ?', {title: 'test'}, function(err, result) {
if (err) throw err;
console.log(result.insertId);
});
if this is valid for rows , then it might be valid for tables.