Use the same job to loop through multiple origins

Use the same job to loop through multiple origins

This example looks at reading from multiple mailboxes for email. Use a variable in the origin connection string. If the job needs to run for another mailbox, it calls the GotoJob function in the “Once After Conn” and pass in the Job's ID. Similar code can be used to write to multiple destinations, for example: Write events to an Exchange calendar for different users.

Once Before Conn Before Operation that returns the current Mailbox to process.

object ScriptedVariable()
{
        string mb = Starfish.GetSetting("Mailboxes");
        Starfish.LogMessage(runCnt.ToString());
        mb = mb.Split(';')[runCnt].Split(',')[0];
        mailBox = mb;
        Starfish.LogMessage("Mailbox: " + mb);
        return mb;
}

Connection String:

@@VAR:vMailbox@@

Once Before Conn Before Operation that retrieves the last Run Date Time value for the User we're processing.

object ScriptedVariable()
{
 //Variable as used in the Origin: @@VAR:userLastRun@@
 string sDt = Starfish.GetSetting("Events-LRD-"+gUserID);
 DateTime dt = Convert.ToDateTime(sDt);
 //Sometimes, the Starfish server and the Source Server clocks are not quite in sync, so I subtract 1 minute from my last run datetime to guarantee I don't miss any records.
 dt = dt.AddMinutes(-1);
 //Add 6 hours to convert to GMT.
 //Starfish.LogMessage(dt.ToString("yyyy-MM-ddTHH:mm:ss+00:00"));
 dt = dt.AddHours(6);
 //Starfish.LogMessage(dt.ToString("yyyy-MM-ddTHH:mm:ss+00:00"));
 
 return dt;
}

Once After Conn After Operation that sets the last Run Date Time value for the User we're processing AND checks to see if we have any more mailboxes to process.

void CSharpProcedure()
{              
 if (!Starfish.PreviewMode)
 {
  Starfish.SaveSetting("Mail-LRD-"+mailBox, DateTime.Now.ToString());
  string mb = Starfish.GetSetting("Mailboxes");
  if (runCnt < mb.Split(';').Length-1)
  {
   runCnt++;
   Starfish.GotoJob("f54baebc-d128-4f9d-9d1a-ac7c88e027fe");
  }
 }
}
    • Related Articles

    • Use Before Save and After Save operations to loop through a single origin record multiple times

      There are many reasons why you might want to loop through a single origin row multiple times. In Act for example, the contact record may contain an Account and one or more Contacts. Another example would be a Note that needs to be related to multiple ...
    • Run Job Options

      Definitions/explanations of the different options for when you wish to run a job. Option Name Description Begin at Row Begin at Row/Leave blank to start at the first row. End at Row End at Row/Leave blank to process through to the end of all rows. ...
    • Creating a New Job

      Jobs are a series of tasks that can be performed against a singe data source. Each Jobs may contain different Stages, which allow you to move the data to different destinations. You may have an unlimited number of Stages per Job, and an unlimited ...
    • Execute When

      OP TYPE WHEN DESCRIPTION Job Initialization PRE OncePerJob Runs once per job before anything else get performed. Use this if you need to call GotoJob() and must first set up variables for your scripted loop. Will only be called once at the beginning ...
    • Execute When

      OP TYPE WHEN DESCRIPTION Job Initialization PRE OncePerJob Runs once per job before anything else get performed. Use this if you need to call GotoJob() and must first set up variables for your scripted loop. Will only be called once at the beginning ...