Log and Ignore Row Error

From Starfish ETL
Jump to navigation Jump to search

Global Error Variable

Add a C# variable to your C# Global so you can use it throughout your job.

string sQuoteToNSError;

Because this is a global variable, it may not reset between rows. I use a "Repeat Each Row" "Pre-Process" to clear my variable.

void CSharpProcedure()
{
	sQuoteToNSError = "";
}

Row Errors

To log an error on a Row, we must ues the Starfish.ErrorMessage property. To continue running a job when a row errors, we need to set Starfish.SuppressError=true; in an "On Row Error" POST-PROCESS.

First, create an "On Row Error" POST-PROCESS. In my post process, I use the globally created C# variable so I can use the Error Message in a later stage that updates the Origin so the people in the Origin can see why their record did not make it to the destination.

//"On Row Error" POST-PROCESS
void CSharpProcedure()
{
    sQuoteToNSError = Starfish.ErrorMessage;
    //Starfish.LogMessage(sQuoteToNSError);
    //There's also a boolean you can set called "SuppressError" which will swallow the error and allwo the process to continue
    //I could check the error message for something and then set that to true if I want to ignore it.
    Starfish.SuppressError=true;
}

The error for me was always happening on the first Stage. I then have a second stage that updates the Origin with the foreign ID or the error, depending on if the first stage is successful or not. I set my origin update stage to not update blank values so it will only set 1 field or the other because only one will have a value.

Other Errors

"Other Errors" are anything you want them to be. For example, if you need a field to have a value/NOT be blank, then you could capture that and pass it back to your source so the people in the source database can see why their record did not make it to the destination database. In this example, I need the AccountID to not be blank. So I check for a blank and if blank, set my error variable to my custom error.

object ScriptedField()
{
	string res = "";
	if (Starfish.OriginData["ACCOUNT_ID"] != null)
	{
        res = Starfish.XRefRead("StoNSAccountIDs",Starfish.OriginData["ACCOUNT_ID"].ToString());
        if (string.IsNullOrEmpty(res))
		{
		    sQuoteToNSError = "Sugar Quote Billing Account Not Found in NetSuite.";
		    Starfish.GotoStage("Update Sugar With NS ID or NS Error");
		}
	}
	return res;
}

Log Error To Origin

I use my global error variable update the Origin record with the error in a custom error field.

object ScriptedField()
{
	return sQuoteToNSError;
}


I also like to update my Origin with the foreign ID and sometimes, a URL to the record in the other system:

object ScriptedField()
{
    string res = "";
	if (!string.IsNullOrEmpty(Starfish.GetStageValue(0,"#ID").ToString()))
	{
	    res = "https://1234567.app.netsuite.com/app/accounting/transactions/salesord.nl?id=" + Starfish.GetStageValue(0,"#ID").ToString();
	}
	return res;
}