Jump to content

Skip record or filtering the database


Recommended Posts

Hi

 

I have a FusionPro template, where I skip records based on the zipcode range using a rule OnRecordStart.

 

The rule is like this:

//Skip records based on postcenter
FusionPro.Composition.composeThisRecord = false;
if (Field("Postcenter") == "KHC") {
   if (Field("Postnr") >= 0 && Field("Postnr") <= 4999) {
       FusionPro.Composition.composeThisRecord = true;
   } else {
       FusionPro.Composition.composeThisRecord = false;
   }
} else if (Field("Postcenter") == "FAC") {
   if ((Field("Postnr") >= 5000 && Field("Postnr") <= 7999) || (Field("Postnr") >= 8700 && Field("Postnr") <= 8799)) {
       FusionPro.Composition.composeThisRecord = true;
   } else {
       FusionPro.Composition.composeThisRecord = false;
   }
} else if (Field("Postcenter") == "ARC") {
   if ((Field("Postnr") >= 8000 && Field("Postnr") <= 8699) || (Field("Postnr") >= 8800 && Field("Postnr") <= 9999)) {
       FusionPro.Composition.composeThisRecord = true;
   } else {
       FusionPro.Composition.composeThisRecord = false;
   }
}

 

The field "Postcenter" is chosen from a drop-down in MarcomCentral.

When previewed it does not always create a preview because the first or last record perhaps is not in the interval defined in the skip record.

 

I was wondering if there was a way to do this with a OnJobStart rule, which instead of skipping records, then filtered the data and the only processed the data with the zip-code range defined.

 

Does anybody know if this is possible?

Link to comment
Share on other sites

If preview is the only thing you are concerned about, you could just put your existing code within an if statement with a condition checking for whether or not the code is being executed in preview. Like so:

if (!IsPreview()){
   //Skip records based on postcenter
   FusionPro.Composition.composeThisRecord = false;
   if (Field("Postcenter") == "KHC") {
       if (Field("Postnr") >= 0 && Field("Postnr") <= 4999) {
           FusionPro.Composition.composeThisRecord = true;
       } else {
           FusionPro.Composition.composeThisRecord = false;
       }
   } else if (Field("Postcenter") == "FAC") {
       if ((Field("Postnr") >= 5000 && Field("Postnr") <= 7999) || (Field("Postnr") >= 8700 && Field("Postnr") <= 8799)) {
           FusionPro.Composition.composeThisRecord = true;
       } else {
           FusionPro.Composition.composeThisRecord = false;
       }
   } else if (Field("Postcenter") == "ARC") {
       if ((Field("Postnr") >= 8000 && Field("Postnr") <= 8699) || (Field("Postnr") >= 8800 && Field("Postnr") <= 9999)) {
           FusionPro.Composition.composeThisRecord = true;
       } else {
           FusionPro.Composition.composeThisRecord = false;
       }
   }
}

Link to comment
Share on other sites

Hi

 

This could be a work around.

 

Still it could be nice to filter the data.

Because my data file contains 1790 records.

When ordering through MarcomCentral the count in the product is 1790, because the data contains this, but the file output only contains the records merged based on the zip-code.

So this is misleading.

Link to comment
Share on other sites

Oh I see, well let me preface this by saying: I have no experience with MarcomCentral and I'm not sure how "product count" is determined in MarcomCentral. Does it also have to be the total number of records or can it be modified?

 

Anyway, with that caveat in mind, you could link to your input data file as an external data file, and run through it to push the values into a sorted array and reference your data from that.

 

Keep in mind I have no way of testing this, but I would think you could potentially trick FP (using the IsPreview function) into thinking it has the correct "product count" by setting an end record number to the value of the array length (during preview only). You'd want to ignore that block of code if it's not in preview though so that it tests all records. Maybe this can get you started (OnJobStart):

if (IsPreview()){
   var data = new ExternalDataFileEx(FusionPro.Composition.inputFileName,',') // assuming comma delimited
   var records = data.recordCount;
   var composeThese = [];

   // Add record numbers to an array of files to compose
   for (var i=1; i<=records; i++){
       var postcenter = data.GetFieldValue(i, "Postcenter");
       var postnr = data.GetFieldValue(i, "Postnr");

       if (postcenter == "KHC") {
           if (postnr >= 0 && postnr <= 4999) {
               composeThese.push(i);
           } 
       } 
       else if (postcenter == "FAC") {
           if ((postnr >= 5000 && postnr <= 7999) || (postnr >= 8700 && postnr <= 8799)) {
               composeThese.push(i);
           } 
       } 
       else if (postcenter == "ARC") {
           if ((postnr >= 8000 && postnr <= 8699) || (postnr >= 8800 && postnr <= 9999)) {
               composeThese.push(i);
           } 
       }
   }

   FusionPro.Composition.endRecordNumber = composeThese.length;
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...