In NetSuite, I have a scripted search of transactions that is expected to return results of several different transaction types. The results are then rendered in an nlobjList. I would like one of the columns of said list to be a link to the transaction that the list row represents.
In all NetSuite examples, this is accomplished something like:
var column = list.addColumn('number', 'text', 'Number', 'left');
column.setURL(nlapiResolveURL('RECORD','salesorder'));
column.addParamToURL('id','id', true);
Unfortunately, transaction is not an acceptable record type to pass to nlapiResolveURL, so I would need to dynamically detect the record type for each row. The setURL function does accept a second Boolean parameter that makes it dynamic per row, but I am not sure how this actually works. There are no examples, and the JSDocs do not explain its usage.
Does anyone have any guidance on generating a list with dynamic URLs in NetSuite?
If you set the dynamic argument to true, then the first argument should be a column listed in the data source that will contain the base URL.
column.setURL('base_url', true);
column.addParamToURL('id','id', true);
Then, on each record of your results, make sure you have a base_url that is set to the url you are looking for.
Note, the following example assumes a regular javascript object instead of the search result object.
rec.base_url = nlapiResolveURL('RECORD', rec.type)
Transaction field is just an abstraction for all transaction types. You can search them but can't load them.
The field you need to retrieve is recordtype. Sample code is below.
var recs = nlapiSearchRecord('transaction',null,null,new nlobjSearchColumn('recordtype'));
for(var i in recs)
url = nlapiResolveURL('RECORD',recs[i].getValue('recordtype'));
Related
If I try to filter the data by using containedIn as below I will be getting empty result because I'm trying to filter from pointer column type userProfile despite that I include the userProfile in the query.
However, I tried to use containedIn directly to another array column in User and seems it was working fine. is this kind of the below queries will not work? and what could be the alternative solutions?
const query = new Parse.Query('User');
query.equalTo('accountType', 'Student');
query.include('userProfile');
// search.subjects is an array
query.containedIn('userProfile.subjectsIds', search.subjects);
Unfortunately, you can't perform containedIn() on included objects. For containedIn() to work it has to be performed on a column of the class you are querying.
So in other words, you will have to perform this query directly on the userProfile class for containedIn() to work
From this article from Martin Hawksey, summarized:
a script bound to the Sheet is published as a web app, a form uses jQuery's $.ajax to send the request to that web app, and the web app handles the parameters into columns of the Sheet with headers matching the names of each param. (the script in this article makes use of PublicLock, which I've changed to ScriptLock)
My problem revolves around checkboxes. Inside the request, I'll see
...fruit=apple&fruit=banana&fruit=cantaloupe...
and the Apps Script will see this as well, passing e to a function handleResponse() which is triggered from doPost(e). To access the values for the parameters in the request, we use e.parameter or e.parameters. I've chosen the latter to accommodate for checkboxes and multiple values for that particular parameter.
What's not happening, though, is exactly that: only the first checkbox value is being sent through. To iterate through params, we use
for (i in headers) {
if (headers[i] == "Timestamp") {
row.push(new Date());
} else {
row.push( e.parameters[headers[i]] );
}
}
to push the values for each parameter that matches a column header into a new array that will be entered as a new row. To do that, Hawksey uses
sheet.getRange(nextRow, 1, 1, row.length).setValues([row])
I guess I'm having trouble understanding what e.parameters does and how I can access the those values. I understand that the parameters property houses the values of each name as arrays, but I can't get an array's entire list of elements to be the value for a cell in a row. Can someone help me understand what e.parameters does, and how I can better get to all of the values I need?
e.parameters is an object where the parameters are the object keys and the values are stored in an array. So, a request like this:
url?fruit=apple&fruit=orange&fruit=lime&animal=giraffe
would yield an object like this:
{'fruit': ['apple', 'orange', 'lime'], 'animal': ['giraffe']}
If you have to put all values for fruit into one cell, you might try:
e.parameters.fruit.join(',')
which will return a string with each value separated by a comma. Then, if you need to separate the values again, you could use String.split() (docs here).
I'm trying to figure out with Breeze how to expand a specific navigation property for all items in an array of entities with a single request.
On this page of the Breeze documentation it shows the following way of achieving this:
var orderEntityType = selectedOrders[0].entityType;
var navProp = orderEntityType.getNavigationProperty("OrderDetails");
var navQuery = EntityQuery
.fromEntityNavigation(selectedOrders, navProp)
.expand("Product");
manager.executeQuery(navQuery).fail(handleFail);
However, when I tried this I get the error
The 'entity' parameter must be an entity
So I looked up in the documentation specifically for the EntityQuery.fromEntityNavigation method and it shows:
// 'employee' is a previously queried employee
var ordersNavProp = employee.entityType.getProperty("Orders");
var query = EntityQuery.fromEntityNavigation(employee, ordersNavProp);
The documentation indicates that it is for a specific entity, not multiple. Which is consistent with the error I'm getting.
Is it possible to get all the navigation properties in a single request, or is the preferred way to iterate over an array making a request for each entity?
Basically, I'm working on filtering a list of items. My goal is that when a user selects a filter it then expands the needed navigation property at that time instead of loading all the data up front.
Thanks for the help.
I think this might be a typo or some out of date information on the navigation properties documentation page. According to the API documentation for EntityQuery.fromEntityNavigation, the first parameter should be a single entity, not an array. Took a look at the breeze code, didn't see any evidence that an array of entities could be passed.
As a workaround, you could construct the query a bit differently. Continuing with the Order/OrderDetails scenario, you could do something like this:
var subsetOfOrders = ..., // array containing the subset of orders whose OrderDetails we need to load
predicates = subsetOfOrders.map(function(order) { return new breeze.Predicate('OrderId', '==', order.OrderId()); }),
predicate = breeze.Predicate.or(predicates),
query = new breeze.EntityQuery('Orders').expand('OrderDetails').where(predicate);
manager.executeQuery(query)...
If you're able to query the order details directly you don't even need expand. Breeze will wire up the freshly loaded OrderDetails to the respective orders entities that are already cached in the entity manager:
var subsetOfOrders = ..., // array containing the subset of orders whose OrderDetails we need to load
predicates = subsetOfOrders.map(function(order) { return new breeze.Predicate('OrderId', '==', order.OrderId()); }),
predicate = breeze.Predicate.or(predicates),
query = new breeze.EntityQuery('OrderDetails').where(predicate);
manager.executeQuery(query)...
This predicate based workaround may or may not be feasible depending on the number of orders you're dealing with. Could end up with a long query string. You could then consider using a dedicated controller action (ie "OrderDetailsByOrderId(int[] orderIds)" and use the withParameters EntityQuery method to load the order details using the new action.
The documentation was in error. I just corrected it.
#Jeremy Danyow offered a superb explanation and a solution. I probably would use his approach to solve a specific use case.
The documentation now discusses the problem and describes yet another approach that might be more appropriate if you were trying to write a general utility.
// create an array of filter criteria (`wherePredicate`) for each order
var predicates = orders.map(function (order) {
return EntityQuery.fromEntityNavigation(order,'OrderDetails')
.wherePredicate;
});
// OR the predicates together
var filter = breeze.Predicate.or(predicates);
EntityQuery.from('OrderDetails')
.where(filter)
.expand('Product')
.using(em).execute().catch(handleFail);
Thanks to you both for identifying the problem and working through it.
I have this function which I believe is following this process:
function verify(){
$.get("map_process.php", function (data) {
verified = $(data).find("marker").eq(-1).attr('verification');
});
}
Get data from php file/db
In the db, find the table "marker"
Find the last record in the table marker
Assign the value of the 'verification' column to the variable verified
This is doing what I want (kind of) but I need to be able to specify what record to get the 'verification' value from, but not by it's position in the table (as more records will be added and the above will just get the last record regardless). Is there another method that is kind of like .eq(x) but will allow me to specifically select a record based on another attr in that record.
eg. Say I want to find the verification value for record 1 through an event listener, and then find the verification value for record 6 through a different event listener.
I have a variable which can distinguish what row I want to get, but how can I incorporate this into the statement above. (i'm thinking instead of .eq(-1)
You can use filter() which can contain as many conditions as you need.
$.get("map_process.php", function (data) {
var myVariable = $(data).find("marker").filter(function(elementIndex, element){
return $(this).attr('someOtherAttribute') === 'valueWanted';
}).attr('verification');
});
Since I'm really not sure what the data looks like or what attribute you need the above is only a guess at how you would need to implement
See filter() API docs
I have a typical FilteringSelect that works when I type in it and I can retrieve the value from the box, which is good. However, I'm trying to determine if I can access to that list of items that it returns.
For instance, if I have the following items in my store:
apple
axe
bananna
And I type in 'a' I want to get the an array that gets me 'apple' and 'axe'.
I'm assuming this will go somewhere in the onKeyPress: function , I'm just not familiar enough with the documentation. I've looked into dijit.byId('selectId') but from there I just don't know the API/documentation well enough
You should look at the API Documentation. There you can see a summary of all events possible. When you read it, you should come to the event called onSearch which returns 3 parameters:
the query
the results
some options
So what you want is the onSearch event and read the results parameter. I made a JSFiddle to show you an example.
Another possible solution is to query the store directly, which can be useful if you don't need the FilteringSelect, but if you just want to get a list of items based on a query. You can also see how that works in my JSFiddle.
EDIT: I Just noticed that you can't access the API documentation. You should really try another browser then, since the API documentation contains a lot of interesting things and is usually the reference for events/methods and properties.
I would have a look at the following properties from the Dojo API page:
https://dojotoolkit.org/api/ (click on dijit/form/FilteringSelect)
query
Defined by dijit/form/_SearchMixin
A query that can be passed to store to initially filter the items. ComboBox overwrites any reference to the searchAttr and sets it to the queryExpr with the user's input substituted.
queryExpr
Defined by dijit/form/_SearchMixin
This specifies what query is sent to the data store, based on what the user has typed. Changing this expression will modify whether the results are only exact matches, a "starting with" match, etc. dojo.data query expression pattern. ${0} will be substituted for the user text. * is used for wildcards. ${0}* means "starts with", ${0} means "contains", ${0} means "is"
searchAttr
Defined by dijit/form/_SearchMixin
Search for items in the data store where this attribute (in the item) matches what the user typed
For example (Haven't tried this so not sure if it will work or not):
* Use attr to retrieve or set dojo properties.
var srchItems = dijit.byId('resistForm').attr("searchAttr","a");