Using Starfish Scripting Class Properties & Methods in C: Difference between revisions

From Starfish ETL
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
See available [[Starfish Scripting Class]] Variables, Properties and Methods.  To use these variables, properties and methods, you must append "Starfish." to the beginning of variable, property or method AND you must use the exact capitalization as found in this wiki.
See available [[Starfish Scripting Class]] Variables, Properties and Methods.  To use these variables, properties and methods, you must append "Starfish." to the beginning of variable, property or method AND you must use the exact capitalization as found in this wiki.


=Generic Example=
Example using the PreviewMode Property and GetSetting and SaveSetting Methods:
Example using the PreviewMode Property and GetSetting and SaveSetting Methods:
<source lang="csharp">
<source lang="csharp">
Line 35: Line 36:




=Hashing Example=
Here are a couple of scripts where I used C# Hashing code to save the hash of a records data so I could skip over the record later if the data was the same.  I could not use only the date_modified field because I was reading and writing the same record.
Here are a couple of scripts where I used C# Hashing code to save the hash of a records data so I could skip over the record later if the data was the same.  I could not use only the date_modified field because I was reading and writing the same record.


Line 49: Line 51:
</source>
</source>


Repeat Each Row Before Operation:
<source lang="csharp">
<source lang="csharp">
void CSharpProcedure()
void CSharpProcedure()
Line 75: Line 79:




Repeat Each Row After Operation
<source lang="csharp">
<source lang="csharp">
void CSharpProcedure()
void CSharpProcedure()

Revision as of 16:03, 9 December 2019

See available Starfish Scripting Class Variables, Properties and Methods. To use these variables, properties and methods, you must append "Starfish." to the beginning of variable, property or method AND you must use the exact capitalization as found in this wiki.

Generic Example

Example using the PreviewMode Property and GetSetting and SaveSetting Methods:

if (!Starfish.PreviewMode)
	{
		//Set the last run datetime for this user.
		Starfish.SaveSetting("Meetings-LRD-"+gUserID, DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss+00:00"));
		
		//Check to see if there are more users to process and if so, restart job.
		string uIDs = Starfish.GetSetting("UserIDs");
		//This Setting is set in the first Job and will restrict runs to only the Admin user.
		bool b = Starfish.GetSetting("AdminUserOnlyTesting_True_OR_False") == "True";
		if (b) {
			uIDs = "ADMIN";
		}
		if (runCnt < uIDs.Split(';').Length-1)
		{
			runCnt++;
			Starfish.GotoJob("e8566f56-69cd-4d65-8835-351de24795e3");
			Starfish.LogMessage("Count: "+ runCnt.ToString());
		} else {
			runCnt = 0;
			Starfish.GotoNextRow();
		}

		string quoteID = Starfish.XRefRead("SLXQuoteIDs",Starfish.OriginData["OPPORTUNITYID"].ToString());
		if (String.IsNullOrEmpty(quoteID))
		{
			quoteID = Starfish.SmartLookup("Quotes","id","[{\"foreignid_c\":\""+Starfish.OriginData["OPPORTUNITYID"].ToString()+"\"}]").ToString();
		}
		return quoteID;
	}


Hashing Example

Here are a couple of scripts where I used C# Hashing code to save the hash of a records data so I could skip over the record later if the data was the same. I could not use only the date_modified field because I was reading and writing the same record.

I had to include some using statements and a function in my .NET Global section.

using System.Text;
using System.Security.Cryptography;

public static byte[] GetHash(string inputString)
{
    HashAlgorithm algorithm = SHA256.Create();
    return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
}


Repeat Each Row Before Operation:

void CSharpProcedure()
{
	string source = Starfish.OriginData["CONTACTID"].ToString()+Starfish.OriginData["ACCOUNTID"].ToString()+Starfish.OriginData["CONTACT_TEAM_SET"].ToString()+Starfish.OriginData["ACCOUNT_TEAM_SET"].ToString()+Starfish.OriginData["ACCOUNT_TEAM_ID"];
    StringBuilder sb = new StringBuilder();
    foreach (byte b in GetHash(source))
	{
        sb.Append(b.ToString("X2"));
	}
	Starfish.LogMessage("newval: "+sb.ToString());
	
	string oldVal = "";
	oldVal = Starfish.XRefRead("hashTeamsToContacts",Starfish.OriginData["CONTACTID"].ToString());
	Starfish.LogMessage("oldval: "+oldVal);
	if(sb.ToString() == oldVal){
		if (!Starfish.PreviewMode)
		{
			Starfish.SaveSetting("AccountTeamsToContactsLDM",Starfish.OriginData["CONTACT_DATE_MODIFIED"].ToString());
		}
		Starfish.GotoNextRow();
	}
    
}


Repeat Each Row After Operation

void CSharpProcedure()
{
	if (!Starfish.PreviewMode)
	{
		Starfish.SaveSetting("AccountTeamsToContactsLDM",Starfish.OriginData["CONTACT_DATE_MODIFIED"].ToString());
		
		//Save the hash of the origin so we can not run the record again if it does not need to be run.
		string source = "";
		source = Starfish.OriginData["CONTACTID"].ToString()+Starfish.OriginData["ACCOUNTID"].ToString()+Starfish.OriginData["CONTACT_TEAM_SET"].ToString()+Starfish.OriginData["ACCOUNT_TEAM_SET"].ToString()+Starfish.OriginData["ACCOUNT_TEAM_ID"].ToString();
		StringBuilder sb = new StringBuilder();
		foreach (byte b in GetHash(source))
		{
			sb.Append(b.ToString("X2"));
		}
		Starfish.LogMessage("newval: "+sb.ToString());
		Starfish.XRefWrite("hashTeamsToContacts",Starfish.OriginData["CONTACTID"].ToString(),sb.ToString());
	}
}