Searching for a Netsuite InboundShipment using SuiteTalk - c#

I am trying to do a search to find out if there is an existing InboundShipment in NetSuite with a given ExternalDocumentValue.
The problem I am having is the ExternalDocumentNumber is a string but the InboundShipmentSearch seems to be wanting a RecordRef array and I do not know what value to create the recordRef with. Here is my current code
InboundShipmentSearchAdvanced isa = new InboundShipmentSearchAdvanced();
// isa.criteria.basic.externalDocumentNumber.searchValue =
InboundShipmentSearchBasic ts = new InboundShipmentSearchBasic();
Client.SearchPreferences.bodyFieldsOnly = false;
isa.criteria = new InboundShipmentSearch();
isa.criteria.basic = new InboundShipmentSearchBasic();
isa.criteria.basic.externalDocumentNumber = new SearchMultiSelectField();
isa.criteria.basic.externalDocumentNumber.#operator =SearchMultiSelectFieldOperator.anyOf;
List<RecordRef> rrlist = new List<RecordRef>();
RecordRef rr = new RecordRef(); RecordType.
rr.name = "HJ_InboundShip_1"; // I don't think this is what I need to prime the record ref.
rrlist.Add(rr);
isa.criteria.basic.externalDocumentNumber.searchValue = rrlist.ToArray();
The issue is since that value is a string and does not really seem to relate to any linked record in the schema, I don't know how to set up the rec. ref for the search. I wondered if anyone had any idea of what I would need to do that.

RecordRef's are a way to define a record lookup for links to existing records, and need instantiation with the either the internalid or externalid of the record. See SuiteAnswers id 10801.

Related

How to create and use a HMM Dynamic Bayesian Network in Bayes Server?

I'm trying to build a prediction module implementing a Hidden Markov Model type DBN in Bayes Server 7 C#. I managed to create the network structure but I'm not sure if its correct because their documentation and examples are not very comprehensive and I also don't fully understand how the prediction is meant to be done in the code after training is complete.
Here is a how my Network creation and training code looks:
var Feature1 = new Variable("Feature1", VariableValueType.Continuous);
var Feature2 = new Variable("Feature2", VariableValueType.Continuous);
var Feature3 = new Variable("Feature3", VariableValueType.Continuous);
var nodeFeatures = new Node("Features", new Variable[] { Feature1, Feature2, Feature3 });
nodeFeatures.TemporalType = TemporalType.Temporal;
var nodeHypothesis = new Node(new Variable("Hypothesis", new string[] { "state1", "state2", "state3" }));
nodeHypothesis.TemporalType = TemporalType.Temporal;
// create network and add nodes
var network = new Network();
network.Nodes.Add(nodeHypothesis);
network.Nodes.Add(nodeFeatures);
// link the Hypothesis node to the Features node within each time slice
network.Links.Add(new Link(nodeHypothesis, nodeFeatures));
// add a temporal link of order 5. This links the Hypothesis node to itself in the next time slice
for (int order = 1; order <= 5; order++)
{
network.Links.Add(new Link(nodeHypothesis, nodeHypothesis, order));
}
var temporalDataReaderCommand = new DataTableDataReaderCommand(evidenceDataTable);
var temporalReaderOptions = new TemporalReaderOptions("CaseId", "Index", TimeValueType.Value);
// here we map variables to database columns
// in this case the variables and database columns have the same name
var temporalVariableReferences = new VariableReference[]
{
new VariableReference(Feature1, ColumnValueType.Value, Feature1.Name),
new VariableReference(Feature2, ColumnValueType.Value, Feature2.Name),
new VariableReference(Feature3, ColumnValueType.Value, Feature3.Name)
};
var evidenceReaderCommand = new EvidenceReaderCommand(
temporalDataReaderCommand,
temporalVariableReferences,
temporalReaderOptions);
// We will use the RelevanceTree algorithm here, as it is optimized for parameter learning
var learning = new ParameterLearning(network, new RelevanceTreeInferenceFactory());
var learningOptions = new ParameterLearningOptions();
// Run the learning algorithm
var result = learning.Learn(evidenceReaderCommand, learningOptions);
And this is my attempt at prediction:
// we will now perform some queries on the network
var inference = new RelevanceTreeInference(network);
var queryOptions = new RelevanceTreeQueryOptions();
var queryOutput = new RelevanceTreeQueryOutput();
int time = 0;
// query a probability variable
var queryHypothesis = new Table(nodeHypothesis, time);
inference.QueryDistributions.Add(queryHypothesis);
double[] inputRow = GetInput();
// set some temporal evidence
inference.Evidence.Set(Feature1, inputRow[0], time);
inference.Evidence.Set(Feature2, inputRow[1], time);
inference.Evidence.Set(Feature3, inputRow[2], time);
inference.Query(queryOptions, queryOutput);
int hypothesizedClassId;
var probability = queryHypothesis.GetMaxValue(out hypothesizedClassId);
Console.WriteLine("hypothesizedClassId = {0}, score = {1}", hypothesizedClassId, probability);
Here I'm not even sure how to "Unroll" the network properly to get the prediction and what value to assign to the variable "time". If someone can shed some light on how this toolkit works, I would greatly appreciate it. Thanks.
The code looks fine except for the network structure, which should look something like this for an HMM (the only change to your code is the links):
var Feature1 = new Variable("Feature1", VariableValueType.Continuous);
var Feature2 = new Variable("Feature2", VariableValueType.Continuous);
var Feature3 = new Variable("Feature3", VariableValueType.Continuous);
var nodeFeatures = new Node("Features", new Variable[] { Feature1, Feature2, Feature3 });
nodeFeatures.TemporalType = TemporalType.Temporal;
var nodeHypothesis = new Node(new Variable("Hypothesis", new string[] { "state1", "state2", "state3" }));
nodeHypothesis.TemporalType = TemporalType.Temporal;
// create network and add nodes
var network = new Network();
network.Nodes.Add(nodeHypothesis);
network.Nodes.Add(nodeFeatures);
// link the Hypothesis node to the Features node within each time slice
network.Links.Add(new Link(nodeHypothesis, nodeFeatures));
// An HMM also has an order 1 link on the latent node
network.Links.Add(new Link(nodeHypothesis, nodeHypothesis, 1));
It is also worth noting the following:
You can add multiple distributions to 'inference.QueryDistributions' and query them all at once
While it is perfectly valid to set evidence manually and then query, see EvidenceReader, DataReader and either DatabaseDataReader or DataTableDataReader, if you want to execute the query over multiple records.
Check out the TimeSeriesMode on ParameterLearningOptions
If you want the 'Most probable explanation' set queryOptions.Propagation = PropagationMethod.Max; // an extension of the Viterbi algorithm for HMMs
Check out the following link:
https://www.bayesserver.com/docs/modeling/time-series-model-types
An Hidden Markov model (as a Bayesian network) has a discrete latent variable and a number of child nodes. In Bayes Server you can combine multiple variables in a child node, much like a standard HMM. In Bayes Server you can also mix and match discrete/continuous nodes, handle missing data, and add additional structure (e.g. mixture of HMM, and many other exotic models).
Regarding prediction, once you have built the structure from the link above, there is a DBN prediction example at https://www.bayesserver.com/code/
(Note that you can predict an individual variable in the future (even if you have missing data), you can predict multiple variables (joint probability) in the future, you can predict how anomalous the time series is (log-likelihood) and for discrete (sequence) predictions you can predict the most probable sequence.)
It it is not clear, ping Bayes Server Support and they will add an example for you.

While trying to add the value i.e. American express to the vendor field, the code is not working

List<ListOrRecordRef> List = new List<ListOrRecordRef>();
ListOrRecordRef RecordRefItem = new ListOrRecordRef();
RecordRefItem.name = "American Express";
RecordRefItem.internalId = "898";
RecordRefItem.typeId = "394";
List.Add(RecordRefItem);
rec.customFieldList = List.ToArray();
WriteResponse response = service.add(rec);
The code is used to add multiselect option of vendor. ex : american express
First of all like Heinz Siahaan said: 'List' is a keyword in C# so you can't create variable with this name.
Second:
ListOrRecordRef RecordRefItem = new ListOrRecordRef();
I'm not sure but name of this method suggest that this line of code creates list of records not one item so you can't use something like this:
RecordRefItem.name = "American Express";
but you should try :
RecordRefItem[i].name = "American Express";
where i is and index of element, but before access it you must create it
found a way its working fine://Note that for multi select option to set we have to take two class:ListOrRecordRef mention the id of the 898:American express&
//SelectCustomFieldRef to mention the field
ListOrRecordRef recordRefItem = new ListOrRecordRef();
recordRefItem.internalId = "898";
SelectCustomFieldRef scfr = new SelectCustomFieldRef();
scfr.scriptId = "custrecord_from_so_customer";
scfr.value = recordRefItem;//set the object value to the mentioned field
customFieldArray[1] = scfr;
rec.customFieldList = customFieldArray

How Lucene.net filter works

i got a piece of code to add filter with Lucene.net but good explanation was not there to understand the code. so here i paste the code for explanation.
List<SearchResults> Searchresults = new List<SearchResults>();
string indexFileLocation = #"C:\o";
Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation);
string[] searchfields = new string[] { "fname", "lname", "dob", "id"};
IndexSearcher indexSearcher = new IndexSearcher(dir);
Filter fil= new QueryWrapperFilter(new TermQuery( new Term(field, "5/12/1998")));
var hits = indexSearcher.Search(QueryMaker(searchString, searchfields), fil);
for (int i = 0; i < hits.Length(); i++)
{
SearchResults result = new SearchResults();
result.fname = hits.Doc(i).GetField("fname").StringValue();
result.lname = hits.Doc(i).GetField("lname").StringValue();
result.dob = hits.Doc(i).GetField("dob").StringValue();
result.id = hits.Doc(i).GetField("id").StringValue();
Searchresults.Add(result);
}
i need explanation for the below two line
Filter fil= new QueryWrapperFilter(new TermQuery( new Term(field, "5/12/1998")));
var hits = indexSearcher.Search(QueryMaker(searchString, searchfields), fil);
i just like to know first lucene search & pull all data and after implement filter or from the beginning lucene pull data based on filter? please guide. thanks.
i just like to know first lucene search & pull all data and after implement filter or from the beginning lucene pull data based on filter? please guide. thanks.
Lucene.Net will perform your search AND your filtered query and after it, it will "merge" the result. The reason to do it I believe is to cache the filtered query, because it will be more likely to have a hit on the next time than the search query.

Dynamic Search using Suitetalk

I am trying to create a C# application (Using suitetalk) that would allow us to search through Netsuite records. The record type will be specified dynamically. Please can you help?
I have checked the webservices and identified that SearchRecord class has many sub classes of type AccountSearch, ItemSearch, etc.
However, I wanted to do these searches dynamically.
AccountSearch acc = new AccountSearch();
SearchResult searchresult = new SearchResult();
searchresult = _service.search(acc);
The above code gives me the list of accounts. But, the AccountSearch is hardcoded here.
The piece of code below works.
SearchRecord search;
SearchRecord searchCriteria;
SearchRecordBasic searchBasicCriteria;
if(recordType.equals(RecordType.account)){
search = new AccountSearchAdvanced();
searchCriteria = new AccountSearch();
searchBasicCriteria = new AccountSearchBasic();
//set criteria on searchBasicCriteria
((AccountSearch) searchCriteria).setBasic((AccountSearchBasic) searchBasicCriteria);
((AccountSearchAdvanced) search).setCriteria((AccountSearch) searchCriteria);
}else if(recordType.equals(RecordType.customer)){
search = new CustomerSearchAdvanced();
searchCriteria = new CustomerSearch();
searchBasicCriteria = new CustomerSearchBasic();
//set criteria on searchBasicCriteria
((CustomerSearch) searchCriteria).setBasic((CustomerSearchBasic) searchBasicCriteria);
((CustomerSearchAdvanced) search).setCriteria((CustomerSearch) searchCriteria);
}else{
search = null;
}
if(search != null) _service.search(search);
But I think a better solution would be to create specific methods for each type of search. That way the code is more readable, plus you avoid all that casting. Then you would have to handle the returned RecordList for each specific record type.

Build dynamic list c#

This code works correctly to make a web service call:
int numberOfGuests = Convert.ToInt32(search.Guest);
var list = new List<Guest>();
Guest adult = new Guest();
adult.Id = 1;
adult.Title = "Mr";
adult.Firstname = "Test";
adult.Surname = "Test";
list.Add(adult);
Guest adult2 = new Guest();
adult2.Id = 2;
adult2.Title = "Mr";
adult2.Firstname = "Test";
adult2.Surname = "Test";
list.Add(adult2);
Guest[] adults = list.ToArray();
How do I build the list dynamically using the numberofguests variable to create the list? The output has to match the output shown exactly else the web service call fails, so adult.id = 1, adult2.id = 2, adult3.id = 3, etc...
Do you know about loops?
for (int i = 1; i <= numberofGuests; i++) {
var adult = new Guest();
adult.Id = i;
adult.Title = "Mr";
adult.Firstname = "Test";
adult.Surname = "Test";
list.Add(adult)
}
This runs the code within the loop once from 1 to numberOfGuests, setting the variable i to the current value.
The Linq way :-)
var list = (from i in Enumerable.Range(1, numberOfGuests)
select new Guest
{
Id = i,
Title = "Mr.",
Firstname = "Test",
Surname = "Test"
}).ToList();
You need a for loop. Or, better yet, a decent C# book -- these are really basics of C#.
Are you asking how to display a list dynamically? I'm not really sure what the question here is about, as the other answers say if you know the value of numberofGuests then you can just use a loop to go through your list.
I suspect you are wondering how to obtain this information in the first place, am I right? If you want to dynamically add controls to a page (your previous post suggest this was ASP.Net I think?), so that you only display the correct number of controls then take a look at these related questions:
Dynamically adding controls in ASP.NET Repeater
ASP.NET - How to dynamically generate Labels

Categories