On Click button Import the data in Kinetic Epicor App studio

Required code import button in Kinetic Application

@aosemwengie1
@dcamlin
@GabeFranco

Epicor Classic Code is given below, required kinetic code

private void btnImport_Click(object sender, System.EventArgs args)
	{
		GetMiscShipDtls();
	}	
	
	private void GetMiscShipDtls()
	{
	    try
	    {
	        EpiDataView edvMscShpHd = (EpiDataView)this.oTrans.EpiDataViews["MscShpHd"];
	        if (edvMscShpHd.Row < 0) 
	            return;
	
	        string JobNum = edvMscShpHd.dataView[0]["JobNum"].ToString();
	        if (JobNum.Length == 0)
	        {
	            MessageBox.Show("Job Num Field is Empty.", "Warning");
	            return;
	        }	
	
	        MiscShipAdapter adapterMiscShip = new MiscShipAdapter(this.oTrans);
	        adapterMiscShip.BOConnect();
	
	        int packNum = (int)edvMscShpHd.dataView[edvMscShpHd.Row]["PackNum"];
	        DataTable dt = GetJobMtlViaBAQ(JobNum);
	        bool hasVal = false;
	
	        if (dt == null) 
	            return;
	
	        if (dt.Rows.Count > 0)
	        {	
	 
	            int i = 1;	          
				foreach (DataRow dr in dt.Rows)
	            {
	                int ShipQty = (int)(dr["Calculated_ShipQty"]);					
					int MtlSeq = (int)(dr["JobMtl_MtlSeq"]);
					int ReqdQty = (int)(dr["Calculated_RequiredQty"]);
					int IssuedQty = (int)(dr["Calculated_IssuedQty"]);
					
	                if (ShipQty > 0)
	                {
	                    if (adapterMiscShip.GetByID(packNum))
	                    {
	                        if (adapterMiscShip.GetNewMscShpDt(packNum))
	                        {
	                            if (adapterMiscShip.OnChangePartNum())
	                            {									
	                                DataRow dRow = adapterMiscShip.MiscShipData.MscShpDt[adapterMiscShip.MiscShipData.MscShpDt.Rows.Count - 1];
	                                dRow["Company"] = dr["JobMtl_Company"].ToString();
									dRow["IUM"] = dr["JobMtl_IUM"].ToString();
	                                dRow["PackNum"] = packNum;
	                                dRow["PackLine"] = i;
	                                dRow["LineType"] = "PART";
									dRow["IssuedQty_c"] = IssuedQty;
									dRow["RequiredQty_c"] = ReqdQty;
									dRow["MtlSeq_c"] = MtlSeq;
									dRow["MiscShipDate_c"] = DateTime.Now.Date;
	                                dRow["HasShipped_c"] = true;
	                                dRow["Quantity"] = ShipQty;
	                                dRow["PartNum"] = dr["JobMtl_PartNum"].ToString();
									dRow["MtlSeq"] = (int)dr["JobMtl_MtlSeq"];
	                                dRow["LineDesc"] = dr["JobMtl_Description"].ToString();
	                                dRow["SysRowID"] = "00000000-0000-0000-0000-000000000000";
	                                dRow["RowMod"] = "A";
	                                adapterMiscShip.Update();
	                                i++;
	                                hasVal = true;
	                            }
	                        }
	                    }
	                }
	            }
	
	            if (hasVal){
	                // SetExtendedProperties();
					this.oTrans.Refresh();		
	                MessageBox.Show("Job imported successfully! ", "Success");
	            }
	            else
	            {
	                MessageBox.Show("This Job# "+JobNum+" was already shipped.", "Warning");
	               return;
	           }
	        }
	        else
	        {
	            MessageBox.Show("Job data was not found.", "Information");
	        }
	    }
	    catch (System.Exception ex)
	    {
	        ExceptionBox.Show(ex);
	    }
	}

	private DataTable GetJobMtlViaBAQ(string JobNum)
	{
	    DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
	    dqa.BOConnect();
	    QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("Get-JobDetailsForMisShipDtl");
	    qeds.ExecutionParameter.Clear();
	    qeds.ExecutionParameter.AddExecutionParameterRow("JobNum",JobNum,"nvarchar",false,Guid.NewGuid(),"A");
	    dqa.ExecuteByID("Get-JobDetailsForMisShipDtl", qeds);
	    if (dqa.QueryResults.Tables["Results"].Rows.Count > 0)
	    {
	        DataTable dtV = dqa.QueryResults.Tables[0];
	        return dtV;
	    }
	    else
	    {
	        return null;
	    }
	}	

Use a function don’t try to do code on the Kinetic layer.

1 Like

@Randy is correct, you will want to convert that to sever side code and make function, which you will then call with an application studio widget. You should be able to find good resources on each of those steps on this site.

If you get stuck at a particular step, post details on the specific issue you are facing and what you have tried. The better you cover the business case and what you have tried, the more likely you are to get help. There is a decent post out there on writing a good post:

Try to remember everyone here has other work and responsibilities to attend to, we aren’t AI agents :grin:

If you need someone to do the project from start to finish, you should look for a consultant.

4 Likes

Done function working in kinetic… :smiley:

signature:
JobNum
PackNum

bool hasVal = false;
DataTable dt = null;
    
    //STEP 1: Execute BAQ and load data
    CallService<Ice.Contracts.DynamicQuerySvcContract>(dq =>
    { 
        Ice.Tablesets.QueryExecutionTableset qets = dq.GetQueryExecutionParametersByID("Get-JobDetailsForMisShipDtl");
        var qParam = qets.ExecutionParameter.FirstOrDefault(x => x.ParameterID.Equals("JobNum", StringComparison.OrdinalIgnoreCase));
        if (qParam != null)
        {
            qParam.ParameterValue = JobNum;   // Set the parameter value
            qParam.RowMod = "U";              // Mark as updated
        }       
        DataSet  ds = dq.ExecuteByID("Get-JobDetailsForMisShipDtl", qets);
        if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
        {
          result = $"No data found for JobNum: {JobNum}";
          return;
        }
        dt = ds.Tables[0];
        if (dt.Rows.Count == 0)
        {
          result = $"No data found for JobNum: {JobNum}";
          return;
        }
        
       /* if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            // Example: return the JobMtl_PartNum of the first row
            result = ds.Tables[0].Rows[0]["JobMtl_PartNum"].ToString();
        }
        else
        {
            result = $"No data found for JobNum: {JobNum}";
        }*/        
          
    });

  //STEP 2: Create Misc Shipment Lines
  CallService<Erp.Contracts.MiscShipSvcContract>(miscShipSvc =>
  {
    // -----------------------------------------
    // STEP 1: Create Misc Shipment Lines Object
    // -----------------------------------------
    Erp.Tablesets.MiscShipTableset ts = miscShipSvc.GetByID(PackNum);
    if (ts == null)
    {
        result = $"PackNum {PackNum} not found.";
        return;
    }
    
    int packLine = ts.MscShpDt.Count > 0
                   ? ts.MscShpDt.Max(x => x.PackLine) + 1
                   : 1;

    // -----------------------------------------
    // STEP 2: Loop BAQ Results
    // -----------------------------------------
    foreach (DataRow dr in dt.Rows)
    {
        int shipQty   = Convert.ToInt32(dr["Calculated_ShipQty"]);
        int mtlSeq    = Convert.ToInt32(dr["JobMtl_MtlSeq"]);
        int reqdQty   = Convert.ToInt32(dr["Calculated_RequiredQty"]);
        int issuedQty = Convert.ToInt32(dr["Calculated_IssuedQty"]);

        if (shipQty <= 0)
            continue;

        // -----------------------------------------
        // STEP 3: Create New Detail Line
        // -----------------------------------------
        miscShipSvc.GetNewMscShpDt(ref ts, PackNum);
        var row = ts.MscShpDt.FirstOrDefault(r => r.RowMod == "A");

        if (row == null)
            continue;

        // -----------------------------------------
        // STEP 4: Populate Required Fields
        // -----------------------------------------
        row.Company  = dr["JobMtl_Company"].ToString();
        row.PackNum  = PackNum;
        row.PackLine = packLine;
        row.LineType = "PART";
        row.PartNum  = dr["JobMtl_PartNum"].ToString();
        row.LineDesc = dr["JobMtl_Description"].ToString();
        row.IUM      = dr["JobMtl_IUM"].ToString();
        row.Quantity = shipQty;
        row.MtlSeq   = mtlSeq;

        // -----------------------------------------
        // STEP 5: Custom Fields
        // -----------------------------------------
        row["IssuedQty_c"]   = issuedQty;
        row["RequiredQty_c"] = reqdQty;
        row["MtlSeq_c"]      = mtlSeq;
        row["MiscShipDate_c"] = DateTime.Today;
        row["HasShipped_c"]  = true;
        row.RowMod = "A";

        // -----------------------------------------
        // STEP 6: Update
        // -----------------------------------------
        miscShipSvc.Update(ref ts);
        packLine++;
        hasVal = true;
    }
});

  // STEP 3: Single Update Call
  if (hasVal)
  {
    result = $"Job# {JobNum} imported successfully!";
  }
  else
  {
    result = $"Job# {JobNum} was already shipped.!";
  } 

1 Like

Glad you had success :slightly_smiling_face: