I have a search page, where user enter fields and click on search button. Then I am making ajax call to Sharepoint 2013 list with search query and fetching data. After fetching data I am binding data to Kendo grid.
This SharePoint list contains different type of fields like: look up, choice, text field. Data from choice column, text field types are getting bind to grid easily, I am able to see the data too. But data from look up columns is not being seen in Kendo Grid.
Instead of data, its showing
[object Object]
Below is the code of ajax call I am making and in success I am binding data to Kendo Grid.
function fetchData(webUrl, filterString){
$.ajax({
url: webUrl +"/_api/web/lists/getByTitle('Inventory')/Items?$filter="+filterString,
method: 'get',
contentType: 'application/json;odata=verbose',
headers:{
'X-RequestDigest': $('#__REQUESTDIGEST').val(),
'Accept': 'application/json;odata=verbose'
},
success: function(data){
var grid = $('#grdInventory').getKendoGrid();
grid.dataSource.data(data.d.results);
grid.refresh();
}
});
}
Below is the screenshot of the Grid: In Grid=
ID, short description, Analytic ID, Analytic Name are text type column
Production status is choice column,
State, Platform are look up column in SharePoint
Below is the screenshot of data being seen in Browser Console:
Can anyone please help me or give me hint of how to display look up column data in Kendo Grid.
That's a standard behavior, Lookup field values in that case represent a complex property and returned as object. Depending on what field from lookup list should be displayed (lets assume Title in our example), you could apply the following filter for returned data before the grid is getting displayed:
var items = data.d.results.map(function(item){
item.State = item.State.Title; //lets get Title from Lookup object
return item;
});
and then bind the data:
var grid = $('#grdInventory').getKendoGrid();
grid.dataSource.data(items);
grid.refresh();
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 trying to create the ability to add custom columns to a tabulator table.
I have a db table where I have a title and field. I extract that info into a json and want that to be added to my table.
fetch("../includes/getCustomColumns.php")
.then(function(response) {
return response.json()
}).then(function(returned) {
window.customColumns = returned
console.log(window.customColumns)
})
Then in my table I have
{
title : "Custom Columns",
columns: [
window.customColumns,
],
}
But I get
Uncaught (in promise) TypeError: Cannot read property 'field' of undefined and tabulator.min.js:2 Invalid column definition option in 'undefined' column: ..
I can see the two columns in the console log and if I copy that into the table it works. I'm wondering if it ss it even possible to add customisable columns to Tabulator or am I simply on the wrong track.
without seeing the code more specifically than what you have here, I'm going to guess that because the fetch() is asynchronous, that window.customColumns is still undefined when you are creating the Tabulator. And then "sometime later" your fetch() sets the value, but it's too late.
You could use addColumn() to programatically add the response to your fetch() when it is received.
I have a button on the Purchase Order record that performs a saved search query on the current record and then uses the http module to send that data via a POST to a url. That url then sends the data posted back as part of the success confirmation. The idea with the saved search is to create a javascript object that contains all the data that I want from the purchase order (main record and items sublist with subrecords) and then to use JSON.stringify to create a JSON payload for the http POST. I can't do this with the currentRecord because if you inspect it it only contains the internal id. This would also prevent me from having to go to the great lengths of writing a lot of code to manually build up a JSON string from the currentRecord.
Unfortunately I don't really understand how to specify the column names in the dynamically created saved search. Sometimes it looks to me like the column names are those from the NetSuite Records Browser and other times the script gives an error (column not found) if I use a column name from the NetSuite Records Browser (for example currencysymbol).
I'm also not sure how to specify columns that appear in sublists or subrecords in sublists. I tried to use item.itemtype but this gave me a column not found error. Just item completes successfully but I'm not sure whether this was really successfull since it is difficult to decode the returned result after the JSON.stringify (it adds a lot of backslashes). Using console.log (for some reason I don't get anything back using the NetSuite log.audit) is also quite difficult, although it looks like it is returning an array with 5 rows. So using item might sort of be successful. I say sort of because I have 3 item lines and it is returning 5 array rows.
So basically I would like to know where one can find the names of the columns to use in NetSuite for a saved search; and also how to specify sublist column names and sublist subrecord column names in a saved search.
/**
* #NApiVersion 2.0
* #NScriptType ClientScript
* #NModuleScope SameAccount
*/
define(['N/ui/dialog', 'N/currentRecord', 'N/record', 'N/url', 'N/http', 'N/search'], function (dialog, rec, record, url, http, s) {
function pageInit(context) {
// All client scripts need at least one dummy function.
} // pageInit
function onButtonClick() {
var currentRecord = rec.get();
// Create a saved search dynamically.
var rs = s.create({
type: s.Type.PURCHASE_ORDER,
filters: [
["mainline", s.Operator.IS, "F"], "and",
["internalid", s.Operator.IS, currentRecord.id]
],
columns: [
"internalid",
"currency",
{
name: "item",
sort: s.Sort.ASC // DESC
}
]
});
var myPostDataObj = rs.run().getRange(0, 1000);
console.log(myPostDataObj);
var headers = {
'Content-Type': 'application/json; charset=utf-8',
};
http.post.promise({
url: 'http://httpbin.org:80/post',
body: JSON.stringify(myPostDataObj),
headers: headers
})
.then(function(response){
console.log('SUCCESS: ' + JSON.stringify(response));
})
.catch(function onRejected(reason) {
console.log('ERROR: ' + JSON.stringify(reason));
})
}
return {
pageInit: pageInit,
onButtonClick: onButtonClick
};
}); // Define
There are two Chrome extensions I suggest you get;
NetSuite Field Explorer. This extension will show you the ids (and values) of all the fields in a NetSuite record.
NetSuite Search Export. This extension will convert/export a saved search to SuiteScript.
For what you're doing, I would create your saved search in the UI, and then export it using the Saved Search Export extension, paste that into your code (where s.create is), and work from there.
The first extension is nice to get to the sublist field ids. Saves a lookup in the record browser.
I am seeing two different behaviors and not sure why. Parts of the question are result of testing solutions implemented from other Q & A.
Summarized Grid create(I only included properties pertinent to question)...
grid setup1
url: jqDataUrl,
datatype: "json",
mtype: "GET",
//loadonce: true
// Default sorting
sortname: typeof prefs.sortCol !== "undefined" ? prefs.sortCol : "LastName",
sortorder: typeof prefs.sortCol !== "undefined" ? prefs.sortOrd : "asc",
sorttype: "text",
sortable: true,
postData: { filters: JSON.stringify({ "groupOp": "AND", "rules": [{ "field": "FirstName", "op": "cn", "data": "max" }]})},
search: true,
results 1 with search: true
When the above grid first loads, it loads with filtered results from postdata filters. If I go to edit url of a resulting row and come back, the record in grid not updated, even though the page/grid above is reloading from scratch from server.
grid setup 2
//same as above but
search: false
results 2 with search: false
When the grid loads this time, the filter not applied. If I go to edit url of a row and come back, the record is updated.
I've read a lot of posts about setting loadonce: true, and changing datatype from local to json and json to local for refreshing, but what I want is for the grid to always load, sort and filter from server data.
Although I understand that free jqGrid does things better, unfortunately, I cannot replace current jqGrid.js file.
My question is two part:
1) I do not see search as an option on wiki here so where is it defined.
2) Can and how do I get the postdata filters to apply on load AND my records updated on the grid after edit?
To answer my own questions:
1) search:true will send _search==true in the http request.
2) The postdata filters(aka where clause when querying data) was being sent in the http request, however, my controller was performing different operations based upon the search: value(aka _search) parsed from http request.
Inside my controller I was setting another property based upon the _search value, and the controller's property was then used to determine whether or not to refresh grid data or use session. It was using session and thus did not update my filtered results after edit.
Another issue I found, was that if I had search:true and manually reset postdata filters to {}, my controller had an error(non thrown w/o try/catch) when it tried to setup the linq with a null, and exited out of grid setup and displayed nothing.
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;
}