As you can tell from all of my earlier questions I'm attempting to learn some NetSuite Suitescript to truly leverage NetSuite. With that being said I've got to where I can search for the max employee number and then act accordingly. Now what I want to do is to search for an email address to see if the one given is a duplicate. Essentially ensure the workflow will not create a new employee record if an employee record already exists with the email address.
I have the following so far...
function checkDuplicate(givenEmail){
var filters = new nlobjSearchFilter('email', null, givenEmail);
var colums = new nlobjSearchColumn('email');
var results = new nlobjSearchRecord('employee', null, filters, columns);
if(results[0].getValue('email') == null) return false;
else return true;
}
Is there a better/easier way? I'll be testing this out.
Your syntax is a bit off. Based on your script, I suggest apply the following modifications:
function checkDuplicate(givenEmail){
var filters = new nlobjSearchFilter('email', null, 'is', givenEmail);
var results = new nlapiSearchRecord('employee', null, filters);
return (results != null);
}
Since you're just checking if there are any matching results, an nlobjColumn isn't needed. Also, if there aren't any matches, nlapiSearchRecord returns a null.
As an additional note, it seems you're still a bit rough on your SuiteScript (at least with the search APIs), so I suggest looking up "Searching with SuiteScript" in the NetSuite Help Center.
Related
I'm trying to search the existing Customers and return the CustomerID if it exists. This is the code I'm using which works:
var CustomerToFind = new Customer
{
MainContact = new Contact
{
Email = new StringSearch { Value = emailIn }
}
};
var sw = new Stopwatch();
sw.Start();
//see if any results
var result = (Customer)soapClient.Get(CustomerToFind);
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
However, I've finding it appears extremely slow to the point of being unusable. For example on the DEMO dataset, on my i7-6700k # 4GHz with 24gb ram and SSD running SQL Server 2016 Developer Edition locally a simple email search takes between 3-4seconds. However on my production dataset with 10k Customer records, it takes over 60 seconds and times out.
Is this typical using Contract based soap? Screen based soap seems much faster and almost instant. If I perform a SQL select on the database tables in Microsoft Management Studio I can also return the result instantly.
Is there a better quick way to query if a Customer with email address = "test#test.com" exists and return the Customer ID?
Try using GetList instead of Get. It's better suited for "search for smth" scenarios.
When using GetList, depending on which endpoint you're using, there are two more optimizations. In Default/5.30.001 endpoint there's a second parameter to GetList which you should set to false. In Default/6.00.001 endpoint there's no second parameter but there is additional property in the entity itself, called ReturnBehavior. Either set it to OnlySpecified and then add *Return to required fields, like this:
var CustomerToFind = new Customer
{
ReturnBehavior = ReturnBehavior.OnlySpecified,
CustomerID = new StringReturn(),
MainContact = new Contact
{
Email = new StringSearch { Value = emailIn }
}
};
or set it to OnlySystem and then use ID on returned entity to request the full entity.
I was wondering if there was a way to add an "Order By" clause when retrieving data from Acumatica through the Web Service API?
IN202500Content IN202500 = oScreen.IN202500GetSchema();
oScreen.IN202500Clear();
Command[] oCmd = new Command[] {IN202500.StockItemSummary.ServiceCommands.EveryInventoryID,
IN202500.StockItemSummary.InventoryID,
IN202500.StockItemSummary.Description,
IN202500.StockItemSummary.ItemStatus,
IN202500.GeneralSettingsItemDefaults.ItemClass,
IN202500.GeneralSettingsItemDefaults.LotSerialClass,
IN202500.PriceCostInfoPriceManagement.DefaultPrice,
};
Filter[] oFilter = new Filter[] {new Filter
{
Field = new Field {ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
FieldName = "LastModifiedDateTime"},
Condition = FilterCondition.GreaterOrEqual,
Value = SyncDate
}
};
String[][] sReturn = oScreen.IN202500Export(oCmd, oFilter, iMaxRecords, true, false);
I would like to sort the results for example by DefaultPrice, so that I can retrieve the Top 200 most expensive items in my list (using iMaxRecords = 200 in this case)
I haven't seen any parameters that allows me to do the sorting yet.
I ran into this when I developed a round robin assignment system and the short answer is using the Acumatica API you cant do a sort on the results you have to do it outside of the API (This info came from a friend closely tied to the Acumatica product).
I came up with two options:
Query your DB directly... There are always reasons not to do this but it is much faster than pulling the result from the API and will allow you to bypass the BQL Acumatica uses and write an SQL statement that does EXACTLY what you want providing a result that is easier to work with than the jagged array Acumatica sends.
You can use some Linq and build a second array[][] that is sorted by price and then trim it to the top 200 (You would need all results from Acumatica first).
// This is rough but should get you there.
string[][] MaxPriceList = sReturn.OrderBy(innerArray =>
{
if () // This is a test to make sure the element is not null
{
decimal price;
if (//test decimal is not null))
return price;
}
return price.MaxValue;
}).Take(200).ToArray(); //Take 200 is a shot but might work
i'm trying to get salesorder records based on date...i'm getting primary information and some sales information also..but while trying to get item details getting null of SalesOrderItemList....but i tried for individual record i'm getting data.
help to solve this one...
Calendar fromDate=Calendar.getInstance();
fromDate.add(Calendar.DATE, -15);
SearchDateField searchDateField=new SearchDateField();
searchDateField.setOperator(SearchDateFieldOperator.after);
searchDateField.setSearchValue(fromDate);
TransactionSearchBasic tsb=new TransactionSearchBasic();
tsb.setDateCreated(searchDateField);
SearchResult res = _port.search(tsb);
RecordList rl=res.getRecordList();
Record[] rr=rl.getRecord();
String salesord=null;
for(Record rcd:rr){
salesord=rcd.getClass().getName();
System.out.println("kkkkkkkkkkkkkkkk :"+salesord);
if(rcd instanceof SalesOrder){
SalesOrder so=(SalesOrder)rcd;
if(so.getSalesRep()!=null){
System.out.println("slaesorder "+ (so.getSalesRep().getName())+"555555 :"+so.getSubsidiary().getName());
}
if(so.getItemList()!=null){
SalesOrderItemList itemlist=(so.getItemList());
System.out.println("temlist");
SalesOrderItem[] items=itemlist.getItem();
if(items!=null){
System.out.println("if items");
for(SalesOrderItem item:items)
{
System.out.println(item.getItem().getName()+" "+item.getQuantity()+" "+item.getDescription()+" "+item.getQuantityOnHand());
}
}
}
}
}
Something changed with NetSuite yesterday or last night(2014-05-09). It's not returning the sub data like it should when you specify bodyFieldsOnly = false in the search preferences.
I've been pulling transactions now for over a year and this just stopped working this morning. Nothing in our php library/code has changed.
I'm not seeing that bodyFieldsOnly parameter set in your code, so you will need to do that. The default is true which only returns the top level sales order information.
Hi guys can anyone shed some light on how to do this please.
I have a userRecord object with various sub-objects in including things like their skills-sets, contracts etc.
I get the record by querying the store for the userId as below.
var userRecord = userStore.findRecord('id', userId);
Next I have a variety of forms with checkboxes in a tabpanel relating to each of the user's sub-objects e.g. Skillsets and Contracts. I am trying to overwrite these on the userRecord with an array on checkboxes that have been checked.
var skillsetCheckBoxes = skillsetPanel.query('checkboxfield[checked=true]');
var skillsets = new Array();
Ext.each(skillsetCheckBoxes, function (skillset)
{
console.log(skillset);
skillsets.push(skillset);
});
I have tried to set the userRecord's engineer's skillset object to be the new array:
userRecord.set(('engineer').skillsets, skillsets);
But when I log the record after doing this it is still the same record I retrieved from findRecord() with no edited fields.
Any help much appreciated,
Thanks!
Hard to say without knowing your model's structure, but your line is clearly wrong. You are using ('engineer').skillsets as the key argument for the set method. Since it's not a string but an array, it won't do anything good.
Your line should rather be something like that:
// You should probably test that there is something in there, or the
// next line could crash...
var engineer = userRecord.get('engineer');
if (engineer) {
userRecord.get('engineer').skillsets = skillsets;
}
I have a property in my index (using the Advanced Database Crawler) for an archive date.
I want to find all items where the date is null or in the future....Date range search will accomplish the second part, but what about the first?
You can't do a null search against Lucene. What I've done in the past is to test for emtpy fields and insert the word "EMPTY" in the index. Then when querying the index you need to add a test that checks for the presence (or absence) of that term. It feels kind of dirty doing it that way but that is the only solution I've been able to find or come up with in the 3 years I've been working with Sitecore and Lucene.
In the DateFieldCrawler class, we modified the following code:
public override string GetValue()
{
if (String.IsNullOrEmpty(_field.Value))
{
return DateTools.DateToString(DateTime.MinValue, DateTools.Resolution.DAY);
}
if (FieldTypeManager.GetField(_field) is DateField)
{
var dateField = new DateField(_field);
if(dateField.DateTime > DateTime.MinValue)
{
return DateTools.DateToString(dateField.DateTime, DateTools.Resolution.DAY);
}
}
return String.Empty;
}
By storing this value, we were able to perform the following queries to include null value dates:
DateRangeSearchParam.DateRange toFirstDate =
new DateRangeSearchParam.DateRange(EVENT_FIRST_DATE,
DateTime.MinValue, toDate.Value);
toFirstDate.InclusiveEnd = false;
eventDates.Add(toFirstDate);