Kinetic - Looping through rows - SelectSerialNumbersEntry

button

1 Like

The true struggle is populating the correct dataview from the CSV file data.

I did have a think maybe the columns need to be matched?

Looking at the JSON I added (this added a row to the SerialNumberSelection dataview and they appeared but the data was wrong…) maybe that can be returned from the function was one complete dataset in the format needed. with the addition to RowMod = "A"

@klincecum

Would this work?

string filePath = @"\\ukdtsappadd01\\97738\\97738\\Companies\\" + this.callContextClient.CurrentCompany + @"\\";
bool locked = true;

// Waits until the file is done being combined
do
{
    locked = false;
    try
    {
        FileStream fs =
            File.Open(Path.Combine(filePath, FileName), FileMode.Open,
            FileAccess.Read, FileShare.None);
        fs.Close();
    }
    catch (IOException ex)
    {
        locked = true;
    }
} while (locked);

using (StreamReader sr = new StreamReader(Path.Combine(filePath, FileName)))
{
    string row = "";
    DataSet thisDS = new DataSet();
    thisDS.Tables.Add("CSVRows");
    DataTable dt = thisDS.Tables["CSVRows"];

    // Set static values for each row
    string company = "this.callContextClient.CurrentCompany";
    bool scraped = false;
    bool voided = false;
    string sourceRowID = Guid.NewGuid();
    string transType = "PUR-STK";
    string partNum = "ABC123" // Static for now until I add a new parm from function.
    bool passedInspection = false;
    bool deselected = true;
    int kbLbrAction = 0;
    bool preventDeselect = false;
    bool preDeselected = true;
    bool notSavedToDB = true;
    string sysRowID = Guid.NewGuid();
    string rowMod = "A";

    int rowCount = 0;
    while (!string.IsNullOrEmpty(row = sr.ReadLine()))
    {
        string[] cols = row.Split(',');

        // Increment row count
        rowCount++;

        // Add new row with serial number as first column
        var dr = dt.NewRow();
        dr["SerialNumber"] = rowCount;
        dr["Company"] = company;
        dr["Scraped"] = scraped;
        dr["Voided"] = voided;
        dr["PartNum"] = cols[0].ToString().Replace("\"", "");
        dr["SNPrefix"] = "";
        dr["SNBaseNumber"] = rowCount;
        dr["SourceRowID"] = sourceRowID;
        dr["TransType"] = transType;
        dr["PassedInspection"] = passedInspection;
        dr["Deselected"] = deselected;
        dr["RawSerialNum"] = partNum;
        dr["KBLbrAction"] = kbLbrAction;
        dr["PreventDeselect"] = preventDeselect;
        dr["PreDeselected"] = preDeselected;
        dr["NotSavedToDB"] = notSavedToDB;
        dr["SysRowID"] = sysRowID;
        dr["RowMod"] = rowMod;

        dt.Rows.Add(dr);
    }

    OutDS = thisDS;
}

looks sound

I assume this works:

string filePath = @"\\ukdtsappadd01\\97738\\97738\\Companies\\" + this.callContextClient.CurrentCompany + @"\\";

but with the @ symbol you don’t need the \\ slashes in the middle

string filePath = @"\\ukdtsappadd01\97738\97738\Companies\" + this.callContextClient.CurrentCompany + @"\";

both can be used…

I’m just letting you know it’s not necessary.

Updated the code.

string filePath = @"\\ukdtsappadd01\97738\97738\Companies\" + this.callContextClient.CurrentCompany + @"\";
bool locked = true;

// Waits until the file is done being combined
do
{
  locked = false;
  try
  {
      FileStream fs =
          File.Open(Path.Combine(filePath, FileName), FileMode.Open,
          FileAccess.Read, FileShare.None);
      fs.Close();
  }
  catch (IOException ex)
  {
      locked = true;
  }
}
while( locked );

using( StreamReader sr = new StreamReader(Path.Combine(filePath, FileName)) )
{
  string row = "";
  DataSet thisDS = new DataSet();
  thisDS.Tables.Add("CSVRows");
  DataTable dt = thisDS.Tables["CSVRows"];
    
  while(!string.IsNullOrEmpty(row = sr.ReadLine()))
  {
    string[] cols = row.Split(','); 
    
    var dr = dt.NewRow();

    // Add the required fields to the DataRow
    dr["Company"] = this.callContextClient.CurrentCompany;
    dr["SerialNumber"] = cols[0];
    dr["Scraped"] = false;
    dr["Voided"] = false;
    dr["PartNum"] = "partNum";
    dr["SNPrefix"] = "";
    dr["SNBaseNumber"] = cols[0];
    dr["SourceRowID"] = Guid.NewGuid();
    dr["TransType"] = "PUR-STK";
    dr["PassedInspection"] = false;
    dr["Deselected"] = true;
    dr["RawSerialNum"] = cols[0];
    dr["KBLbrAction"] = 0;
    dr["PreventDeselect"] = false;
    dr["PreDeselected"] = true;
    dr["NotSavedToDB"] = true;
    dr["SysRowID"] = Guid.NewGuid();
    dr["RowMod"] = "A";
    
    dt.Rows.Add(dr);
  }
  
  OutDS = thisDS;
}

image

image

After updating the function code to above… :frowning:

what was it before ?

What @hmwillett shared just modified filePath

Me after following this thread

Welcome to the rabbit hole.

Jose:

He’s not hoppin’ in this one, lol.

It’s all you

Don’t blame him one bit.

Sorry @aarong , but I’m out too. I’m working through a broken screen because I don’t have serial numbers set up.

I tried to set some parts up for that but I don’t see that screen in qty adjustment, and for
some reason I can’t get my PO to receive.

Yous gottsta turn on serial tracking in site config dawg.

1 Like

I just looked, still not seeing it. Un momento.

This Kinetic Web UI is pure junk.

I got it set up, but no matter what I do, it will not give me my layer.

I even used the big hammer.

Some kind of cache issue? I dunno. If it is, it’s on the server, because the request is happening
but no layer returned. It even returned the layer I deleted from before for a while.

I can’t help now even if I wanted to. What a $@#@# joke.

I mean look at this. When you click it to open serial numbers, it does a GetApp Request twice.

Why?

{
	"id": "Erp.UI.SelectSerialNumbersEntry",
	"properties": {
		"deviceType": "Desktop",
		"layers": [],
		"mode": "",
		"applicationType": "view",
		"additionalContext": {
			"inPreviewMode": false,
			"menuId": "323dds"
		}
	}
}
{
	"id": "Erp.UI.SelectSerialNumbersEntry",
	"properties": {
		"deviceType": "Desktop",
		"layers": [],
		"mode": null,
		"applicationType": "view",
		"additionalContext": {
			"doValidation": true,
			"menuId": "323dds"
		},
		"checkDuplicateIds": false,
		"debug": false
	}
}

What that menuId is, no clue. No menu ID in my environment named that.
Earlier it looked for “assass”, no joke.

Damn request is returning status 304…not modified, use cached version.

We need to be able to turn that crap off when necessary.