Example: Retrieving a Target list

Copy
// This shows an example of retrieving a target list, cycling through the targets
// and marking any excluded targets as being included

<!-- #include file ="sagecrm.js" -->
<%

TargetBlock = CRM.TargetLists;
// Get the TargetBlock COM Object from the CRM base object

TargetBlock.TargetListID = Request.QueryString("Key25");
// Set the id that we want to look for

TargetQuery = TargetBlock.Retrieve();
// Retrieve the target list

while (!TargetQuery.EOF)
    {
        if (TargetQuery.FieldValue("DData_ShortStr") == "Excluded") 
        // If this target is excluded, then
        
        {
            TargetBlock.Include(TargetQuery.FieldValue("Pers_PersonID"));
            // Include this target
            // This particular target list is a Person target list
            // If a Company target list, then use the Comp_CompanyID field
            // If a Lead target list, then use the Lead_LeadID field
            
        }
        
        TargetQuery.Next(); 
        // Move to next target
        
    }
    
    // For the moment, we always return to the Actions page whether successful or not.
    // 580 is the action number to go back to the target list browser page
    // 585 is the action number to go back to the target list actions page
    
if (TargetBlock.Save())
    { 
        // Save the target list
        Response.Redirect(CRM.URL(585));
    }
    
else
    {
        Response.Redirect(CRM.URL(585));
    }

%>