NetSuite Web Services Custom Field in Searches - c#

I cant seem to pull the custom field values of a transaction search using Web Services.
searchTransaction.savedSearchId = "2017";
SearchResult result = netsuite.search(searchTransaction);
if(result.status.isSuccess)
{
SearchRow[] searchRows = result.searchRowList;
if(searchRows != null && searchRows.Length >= 1)
{
for (int i = 0; i < searchRows.Length; i++)
{
TransactionSearchRow transactionRow = (TransactionSearchRow)searchRows[i];
var iid = transactionRow.basic.internalId[0].searchValue;
double amount = transactionRow.basic.amount[0].searchValue;
string custfild = transactionRow.basic.customFieldList[0].scriptId;
Console.WriteLine("\n Transaction ID: " + iid.internalId);
Console.WriteLine("\n Amount: " + amount.ToString());
Console.WriteLine("\n customfield: " + custfield.ToString());
}
}
}
I know that the field is being returned because I can see it in the xml response. And custfield.ToString() does return the internal ID of the custom field.
I just cant seem to get the actual value.

Figured it out, posting in case anyone else has the same question:
searchTransaction.savedSearchId = "2017";
SearchResult result = netsuite.search(searchTransaction);
if(result.status.isSuccess)
{
SearchRow[] searchRows = result.searchRowList;
if(searchRows != null && searchRows.Length >= 1)
{
for (int i = 0; i < searchRows.Length; i++)
{
TransactionSearchRow transactionRow = (TransactionSearchRow)searchRows[i];
var iid = transactionRow.basic.internalId[0].searchValue;
double amount = transactionRow.basic.amount[0].searchValue;
string custfild = transactionRow.basic.customFieldList[0].scriptId;
SearchColumnStringCustomField custfild = (SearchColumnStringCustomField)transactionRow.basic.customFieldList[0];
Console.WriteLine("\n Transaction ID: " + iid.internalId);
Console.WriteLine("\n Amount: " + amount.ToString());
Console.WriteLine("\n custfild: " + custfild.searchValue);
}
}
}

Related

C# - Cannot populate grandchild of second child in tree view

I am populating a treeview from an arrayList and I am not able to populate the grandchildren of the second child.
I was going for something like this
parent
- child1
- gc1
- gc2
- child2
- gc1
- gc2
But I am stuck with only just populating the child2 as I am having exceptions (ArgumentOutOfRangeException) when trying to populate the grandchildren of the second child
string currentDatabaseParent = "";
string currentSchemaParent = "";
string currentTableParent = "";
int databasecount = 0;
int schemacount = 0;
int tablecount = 0;
foreach (var schema in schemaArr)
{
int order = Array.IndexOf(schemaArr, schema);
if ((schema.column_name != "Number") && (schema.schema_name != "INFORMATION_SCHEMA") && (schema.database_name != "SAMPLE_DATA"))
{
if ((currentDatabaseParent == "") || (currentDatabaseParent != schema.database_name))
{
treeViewSchemaList.Nodes.Add(schema.database_name);
sb.AppendLine(schema.database_name);
currentDatabaseParent = schema.database_name;
}
else if (currentDatabaseParent != schema.database_name)
{
treeViewSchemaList.Nodes.Add(schema.database_name);
sb.AppendLine(schema.database_name);
currentDatabaseParent = schema.database_name;
databasecount = databasecount + 1;
schemacount = 0;
tablecount = 0;
}
if ((currentSchemaParent == ""))
{
treeViewSchemaList.Nodes[schemacount].Nodes.Add(schema.schema_name);
sb.AppendLine(" - " + schema.schema_name);
currentSchemaParent = schema.schema_name;
}
else if (currentSchemaParent != schema.schema_name)
{
treeViewSchemaList.Nodes[schemacount].Nodes.Add(schema.schema_name);
sb.AppendLine(" - " + schema.schema_name);
currentSchemaParent = schema.schema_name;
schemacount = schemacount + 1;
}
if (currentTableParent == "")
{
treeViewSchemaList.Nodes[schemacount].Nodes[tablecount].Nodes.Add(schema.table_name);
sb.AppendLine(" - " + schema.table_name);
currentTableParent = schema.table_name;
}
else if (currentTableParent != schema.table_name)
{
treeViewSchemaList.Nodes[schemacount].Nodes[tablecount].Nodes.Add(schema.table_name);
sb.AppendLine(" - " + schema.table_name);
currentTableParent = schema.table_name;
tablecount = tablecount + 1;
}
//DataType dataType = new DataType();
//dataType = JsonConvert.DeserializeObject<DataType>(schema.data_type);
//sb.AppendLine(" - " + schema.column_name + "(" + dataType.Type + ")");
//treeViewSchemaList.Nodes[databasecount].Nodes[schemacount].Nodes[tablecount].Nodes.Add(schema.column_name + "(" + schema.data_type + ")");
}
}
The code stucks to this when viewed from the StringBuilder
parent
- child1
- gc1
- gc2
- child2
I have already tried modifying some code by manipulating the count variables but still can't get to work

how to get more than 5000 entities by using Factories GetByFilter method with prestasharp

Library Version:
1.2.9
NuGet Package Url:
https://www.nuget.org/packages/PrestaSharp/1.2.9
Prestashop version:
1.7.7.0
Describe the Bug:
PrestaSharp GetByFilter with pagination always return same entity list
Since ProductFactory's GetByFilter method returns null if there are more than 5000 products that match the filter. I decide to get them by pagination like this
_productFactory.GetIdsByFilter(filter, null, "[" + startingIndex.ToString() + "," + count.ToString() + "]");
but even if startingIndex(because of a loop) changes the result is the same
Full code:
filter.Add("date_upd", "[" + dFrom + "," + dTo + "]");
int i = 0;
List<long> AllProducts = new List<long>();
List<long> products;
while (true) // this loop never breaks
{
int startingIndex = i++ * count;
products = _productFactory.GetIdsByFilter(filter, null, "[" + startingIndex.ToString() + "," + (count).ToString() + "]"); // returns same products in every iteration
if (products?.Any() == true) // to check the list is not empty
{
AllProducts.AddRange(products);
if (products.Count < count)
{
break;
}
}
else
break;
}
You just have to remove the brackets from the 'limit' parameter. It is an error in the Github documentation when they give the example with brackets. Here's an own implementation where I send multiple requests in parallel to speed up the processing, regards.
public async Task<List<PS_Entity>> GetElements(int pageSize = 100) {
try {
var numberOfElements = factory.GetIds().Count;
var numberOfParallelTasks = numberOfElements >= pageSize ? numberOfElements / pageSize : 1;
var loadElementsTasks = Enumerable.Range(0, numberOfParallelTasks).Select(taskNumber => factory.GetByFilterAsync(null, "id_ASC", $"{taskNumber * pageSize},{pageSize}")).ToList();
if (numberOfElements % pageSize != 0) {
var skiped = numberOfParallelTasks * pageSize;
loadElementsTasks.Add(factory.GetByFilterAsync(null, "id_ASC", $"{skiped},{numberOfElements - skiped}"));
}
var elements = (await Task.WhenAll(loadElementsTasks)).SelectMany(elements => elements).ToList();
return elements;
} catch (PrestaSharpException e) {
if ((int)e.ResponseHttpStatusCode == 404)
Console.WriteLine($"No existen {RemoveFactoryFromName(factory)}'s.");
return new List<PS_Entity>();
}
}

C# Loop over all possible values, when not found increase value and continue

I need to send a request for every supplier code to a webservice (i know that sounds crazy but the owner designed it this way).
The supplier code format is:
30X1X1XXXXX1
You can check what i did so far (github link: https://github.com/rareba/SiapWebServices_Library/blob/master/SiapWebServices_Library/SiapWebServicesFornitore.cs)
public static List<StructAnaFornitoreOut> Get_All_Suppliers(WebServicesFornitoreClient client, StructLogin loginCredentials, string showSuspended = "N", string searchType = "R")
{
var supplier_list = new List<StructAnaFornitoreOut>();
var supplier_retrived = new StructAnaFornitoreOut
{
esito = new StructEsito
{
stato = "OK",
}
};
int KO_Count = 0;
int conto = 1;
int sottoconto = 1;
int codice = 0;
string codFornitore = Generate_Supplier_Code_String(codice, sottoconto, conto);
var search = new StructAnaFornitoreIn
{
IAnaFornitore = new StructAnaFornitore
{
codice = codFornitore
},
IAzione = "C",
//vModRicerca = new string[] { "COD_FIS","PAR_IVA","ALT_SIS" }
};
while (KO_Count < 10)
{
while (KO_Count < 10)
{
while (KO_Count < 10)
{
supplier_retrived = client.gestioneAnagraficaFornitore(loginCredentials, search);
if (supplier_retrived.esito.stato == "KO")
{
KO_Count++;
}
else
{
supplier_list.Add(supplier_retrived);
codFornitore = Generate_Supplier_Code_String(codice, sottoconto, conto);
Console.WriteLine(codFornitore);
codice++;
search.IAnaFornitore.codice = codFornitore;
}
}
KO_Count = 0;
sottoconto++;
}
KO_Count = 0;
conto++;
}
return supplier_list;
}
// Returns a supplier code string increased by 1
public static string Generate_Supplier_Code_String(int codice = 0, int sottoconto = 1, int conto = 1, string mastro = "30")
{
codice++;
string string_conto = " ";
string string_sottoconto = " ";
string string_codice = " ";
if (conto > 9)
{
string_conto = "";
}
if (sottoconto > 9)
{
string_sottoconto = "";
}
if (codice > 9)
{
string_codice = " ";
}
else if (codice > 99)
{
string_codice = " ";
}
else if (codice > 999)
{
string_codice = " ";
}
else if (codice > 9999)
{
string_codice = " ";
}
else if (codice > 99999)
{
string_codice = " ";
}
else if (codice >= 999999)
{
string_codice = "";
}
string customercode = mastro + string_conto + conto + string_sottoconto + sottoconto + string_codice + codice;
return customercode;
}
However this doesn't work at all: it stops at supplier 30 1 1 100 and starts increasing sottoconto like there is no tomorrow.
The idea should be to do something like:
- Get the supplier data
- Increase codice by 1
- If for 10 times you get nothing (esito.status = "KO") then increase sottoconto and start again from codice = 1
- If after incresing sottoconto you still get nothing for 10 times then increase conto and start again from codice = 0

How to get the Radio button values from PDF form using PDFbox (C#)

How to get the Radio button values from PDF form using PDFbox (C#)
In Java :
doc = PDDocument.load("C:\\Users\\347702\\Desktop\\sample_form.pdf");
List pages = doc.getDocumentCatalog().getAllPages();
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
List FieldTypes = form.getFields();
PDField pdfFields;
for (int i = 0; i < FieldTypes.size(); i++) {
pdfFields = (PDField) ((List) FieldTypes).get(i);
if (pdfFields instanceof PDRadioCollection)
{
String iAsString = Integer.toString(k);
System.out.println(iAsString);
type = "RadioButton";
System.out.println("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
List kids = pdfFields.getKids();
for (Object kid : kids) {
if (kid instanceof PDCheckbox) {
PDCheckbox checkbox = (PDCheckbox) kid;
String Name = checkbox.getOnValue();
System.out.println(Name);
}
}
The above java code has been successfully working (successfully returns the children of Radiobuttons) but when the same logic is been implemented in c# its not running as expected
below is my c# code :
else if (pdfFields is PDRadioCollection)
{
System.Console.WriteLine("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
List kids = pdfFields.getKids();
System.Console.WriteLine(kids);
for (int w = 0; w < kids.size(); w++)
{
kids.get(w);
System.Console.WriteLine(kids.get(w)); ---- > Return null
System.Console.WriteLine(kids.get(w).ToString()); -- > Return null
}
}
Can any help out in this please
Thanks
At last got it work : here it is ::
C# : Need to type case with IEnumerable :
else if (pdfFields is PDRadioCollection)
{
System.Console.WriteLine("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
System.Collections.IEnumerable kids = (System.Collections.IEnumerable)pdfFields.getKids();
System.Console.WriteLine(kids);
foreach (object kid in kids)
{
PDCheckbox checkbox = (PDCheckbox)kid;
checkbox.check();
}

ascending order foreach

I am trying to check for ascending order in this array
But not sure how to use a foreach
foreach (double d in dSize)
{
if (dSize.ToString() != null)
{
double dSize1;
string str1 = dSize.ToString();
bool success1 = double.TryParse(str1, out dSize1);
if ( dSize < 0.0)
{
errMsg1 = " data grid should contain number >= 0";
}
//else
//{
// errMsg1 = " data grid must be entered";
//}
}
*if (inputs.dSize[rowCount] <= inputs.dSize[rowCount - 1])
{
errMsg = "value in row " + (rowCount + 1) + " should be greater than the value in row " + rowCount;
}
}*
swRpt.WriteLine(errMsg);
}
I've done the second part using a for loop. Would like to change it to a foreach
You just need to remember the previous value from one iteration to the next. The issue with using foreach for this (as opposed to the raw iterator) is that you need a special case for the first value:
Double lastDouble = null;
foreach(double d in dSize) {
if ((lastDouble != null) && (lastDouble > d)) {
errMsg = "value out of sequence";
break;
}
lastDouble = d;
}
but then you've lost the row number for the error. You could also prime your last value from the first entry and skip one using LINQ
double lastDouble = dSize.First();
foreach(double d in dSize.Skip(1)) {
if (lastDouble > d) {
errMsg = "value out of sequence";
break;
}
lastDouble = d;
}
Why not...
for(int i = dSize.Length-1; i>=0;i--)
{
double d = dSize[i];
...
...
...
}

Categories

Resources