0

I'm after some help getting a couple of my variables to present the expected information.

At present, I've added @fibreMaxTest and @FibreMax to determine if a customer has our FibreMax product. If they do, I want to be able to print term-specific content within the body copy of the email, like this:

%%[IF @hasFibreMax=="False" AND @subscriptionTerm !="No Term" AND @unsolicitedSale=="True" AND @offerType==@youChoose AND @hasDoubleDip=='True' THEN]%% 
The term of the Agreement for power and broadband services (Term) is %%=v(@subscriptionTerm)=%% months.%%[IF @hasBroadbandPhone=="True" OR @hasLPG=="True" OR @hasGas=="True" THEN]%% There is no fixed term for %%=v(@gasPhoneTermsList)=%% services.%%[ENDIF]%% This Term starts at the end of your cancellation period, or when your broadband and power services have both been connected with Trustpower, whichever is the later. In addition, as you have chosen a [Fibre Speed] fibre service and fibre is not yet connected at your address, and you have elected to take a %%=v(@otherBroadbandName)=%% broadband service from Trustpower until your fibre is connected, your term will commence when your %%=v(@otherBroadbandName)=%% broadband service is connected, and you will pay the %%=v(@otherBroadbandName)=%% broadband prices from the commencement of the Agreement until fibre is connected, and the applicable fibre price for your [Fibre Speed] fibre plan after fibre connection. Please find attached the full terms and conditions for your services. We'll order your %%=v(@incentiveName)=%% for you once your term commences.
%%[ENDIF]%%

How I have achieved this previously is by setting all my variables with SFSC fields from the Quote Line object and then using ELSEIFs throughout to get the customers products i.e. IF @productFamily == "power" THEN SET @hasPower = "True". I've attached the entire script below but also pulled out the new INDEXOF function and variables directly below:

ELSEIF @productFamily == "Broadband" THEN
     SET @currentConnectionType = field(@quoteLine, "Current_Connection_Type__c")
     SET @currentProvider = field(@quoteLine, "Current_Provider_Name__c")
     IF indexof(@productName,"FibreMax") >0 and @productType != "Phone" THEN
      Set @hasUFB = "True"
      SET @hasFibreMax = "True"
      SET @fibreMaxTest = "Test content: FibreMax"
      SET @broadbandProductName = UpperCase(@productName)
      SET @broadbandPrice = FormatNumber(@specialPrice,"#0.00")
      SET @UFBQuoteLineId =field(@quoteLine,"Id")
     ELSEIF indexof(@productCategory,"100/20") <0 and @productCategory == "Fibre" and @productType != "Phone" THEN
     Set @hasUFB = "True"
      SET @hasFibreMax = "False"
      SET @fibreMaxTest = "Test content: Not Fibre"
      SET @broadbandProductName = UpperCase(@productName)
      SET @broadbandPrice = FormatNumber(@specialPrice,"#0.00")
      SET @UFBQuoteLineId =field(@quoteLine,"Id")

What I've attempted to do above is find all instances of 'FibreMax' and '100/20' and set the @hasFibre variables from that. When I tried to debug by printing the @hasFibreMax, @fibreMaxTest I was unable to render any value within the email.

Full script added below for context:

set @quoteLineRowSet = RetrieveSalesforceObjects(
   "SBQQ__QuoteLine__c",
"Id,SBQQ__Product__c,Product_Category__c,SBQQ__ProductFamily__c,Product_Commercial_Name__c,Product_Type__c,SBQQ__ProductCode__c,Current_Connection_Type__c,Current_Provider_Name__c,Mobile_Transfer_Date__c,SBQQ__StartDate__c,SBQQ__SpecialPrice__c,FavouriteCountry__c,Favourite_Phone_Number__c,Service_Rate__c,Service_Name__c,Service_Measure__c,Mobile_Transfer__c,SBQQ__RequiredBy__c,Incentive_Level__c",
   "SBQQ__Quote__c", "=", @quoteId,"SBQQ__Quantity__c",">=","1" )
if RowCount(@quoteLineRowSet) > 1 then /* if multiple records are found then loop through*/
 for @i = 1 to RowCount(@quoteLineRowSet) do
   set @quoteLine = row(@quoteLineRowSet, @i)
   SET @productFamily = field(@quoteLine,"SBQQ__ProductFamily__c")
   SET @productType = field(@quoteLine,"Product_Type__c")
   SET @productCategory = field(@quoteLine,"Product_Category__c")
   SET @productName = field(@quoteLine,"Product_Commercial_Name__c")
   SET @specialPrice = field(@quoteLine,"SBQQ__SpecialPrice__c")
   SET @productCode = field(@quoteLine,"SBQQ__ProductCode__c")
   SET @incentiveTier = field(@quoteLine,"Incentive_Level__c")
   IF @productFamily == "Power" THEN
    Set @hasPower = "True"
    IF @productCategory =="Electricity" THEN
     SET @elecProductName = CONCAT(UpperCase(@productType)," POWER RATE")
     SET @powerServiceNameList = replace(field(@quoteLine,"Service_Name__c"),char(10),"**")
     SET @powerServiceMeasureList = replace(field(@quoteLine,"Service_Measure__c"),char(10),"**")
     SET @powerServiceRateList = replace(field(@quoteLine,"Service_Rate__c"),char(10),"**")
    ELSEIF @productCategory=="Other" AND @productType=="Fee" THEN
     SET @elecReconnectionFeeName = UpperCase(@productName)
     SET @electReconnectionFeePrice = FormatNumber(@specialPrice,"#0.00")
    ENDIF
   ELSEIF @productFamily == "Broadband" THEN
     SET @currentConnectionType = field(@quoteLine, "Current_Connection_Type__c")
     SET @currentProvider = field(@quoteLine, "Current_Provider_Name__c")
     IF indexof(@productName,"FibreMax") >0 and @productCategory == "Fibre" and @productType != "Phone" THEN
      Set @hasUFB = "True"
      SET @hasFibreMax = "True"
      SET @fibreMaxTest = "Test content"
      SET @broadbandProductName = UpperCase(@productName)
      SET @broadbandPrice = FormatNumber(@specialPrice,"#0.00")
      SET @UFBQuoteLineId =field(@quoteLine,"Id")
     ELSEIF indexof(@productCategory,"100/20") <0 and @productCategory == "Fibre" and @productType != "Phone" THEN
     Set @hasUFB = "True"
      SET @hasFibreMax = "True"
      SET @broadbandProductName = UpperCase(@productName)
      SET @broadbandPrice = FormatNumber(@specialPrice,"#0.00")
      SET @UFBQuoteLineId =field(@quoteLine,"Id")
     ELSEIF @productCategory == "Copper" and @productType != "Phone" THEN
      Set @hasDSL = "True"
      SET @otherBroadbandName = UpperCase(@productName)
      SET @otherBroadbandPrice = FormatNumber(@specialPrice,"#0.00")
      SET @CopperQuoteLineId =field(@quoteLine,"Id")
     ELSEIF @productCategory == "Wireless" and @productType != "Phone" THEN
      Set @hasWBB = "True"
      SET @otherBroadbandName = UpperCase(@productName)
      SET @otherBroadbandPrice = FormatNumber(@specialPrice,"#0.00")
      SET @WBBQuoteLineId =field(@quoteLine,"Id")
     ELSEIF @productCategory =="Add-on" THEN
      IF empty (@addOnParent1QuoteLineId) OR  @addOnParent1QuoteLineId == field(@quoteLine, "SBQQ__RequiredBy__c") THEN
        SET @addOnParent1QuoteLineId = field(@quoteLine, "SBQQ__RequiredBy__c")
        SET @hasAddOn = "True"
        IF @productType=="Favourite" THEN
         IF @productName=="Favourite Number" THEN
           SET @hasFavNumber = "True"
           SET @favNumberList = CONCAT(@favNumberList ,field(@quoteLine,"Favourite_Phone_Number__c"),"**")
           SET @favNumberRowset = BuildRowsetFromString(@favNumberList,"**")
           SET @rowCountFavNumber = RowCount(@favNumberRowset)
         ELSEIF @productName=="Favourite Country" THEN
          SET @hasFavCountry = "True"
          SET @favCountryList = CONCAT(@favCountryList ,field(@quoteLine,"FavouriteCountry__c"),"**")
          SET @favCountryRowset = BuildRowsetFromString(@favCountryList,"**")
          SET @rowCountFavCountry = RowCount(@favCountryRowset)
         ENDIF
        ELSE
          SET @extraAddOnsList = CONCAT(@extraAddOnsList ,UpperCase(@productName),"**")
          SET @extraAddOnsRowset = BuildRowsetFromString(@extraAddOnsList,"**")
          SET @extraAddOnsPriceList = CONCAT(@extraAddOnsPriceList , FormatNumber(@specialPrice,"N"), "**")
          SET @extraAddOnsPriceRowset = BuildRowsetFromString(@extraAddOnsPriceList,"**")
          SET @rowCountAddOns = RowCount(@extraAddOnsRowset)
        ENDIF
      ELSE
       SET @hasAddOn2 = "True"
       IF @productType=="Favourite" THEN 
         IF @productName=="Favourite Number" THEN
           SET @hasFavNumber2 = "True"
           SET @favNumberList2 = CONCAT(@favNumberList2 ,field(@quoteLine,"Favourite_Phone_Number__c"),"**")
           SET @favNumberRowset2 = BuildRowsetFromString(@favNumberList2,"**")
           SET @rowCountFavNumber2 = RowCount(@favNumberRowset2)
         ELSEIF @productName=="Favourite Country" THEN
          SET @hasFavCountry2 = "True"
          SET @favCountryList2 = CONCAT(@favCountryList2 ,field(@quoteLine,"FavouriteCountry__c"),"**")
          SET @favCountryRowset2 = BuildRowsetFromString(@favCountryList2,"**")
          SET @rowCountFavCountry2 = RowCount(@favCountryRowset2)
         ENDIF
        ELSE
          SET @extraAddOnsList2 = CONCAT(@extraAddOnsList2 ,UpperCase(@productName),"**")
          SET @extraAddOnsRowset2 = BuildRowsetFromString(@extraAddOnsList2,"**")
          SET @extraAddOnsPriceList2 = CONCAT(@extraAddOnsPriceList2 ,FormatNumber(@specialPrice,"N"),"**")
          SET @extraAddOnsPriceRowset2 = BuildRowsetFromString(@extraAddOnsPriceList2,"**")
          SET @rowCountAddOns2 = RowCount(@extraAddOnsRowset2)
        ENDIF
      ENDIF
     ENDIF   
     IF @productType == "Naked" THEN
      Set @hasBroadband = "True"
     ELSEIF @productType == "Clothed" THEN
      Set @hasBroadbandPhone = "True"
     ELSEIF @productType == "Phone" THEN
      Set @hasPhoneOnly = "True"
      SET @phoneProductName = UpperCase(@productName)
      SET @phoneProductPrice = FormatNumber(@specialPrice,"#0.00")
     ENDIF   
   ELSEIF @productFamily == "Mobile" THEN
    Set @hasMobile = "True"
    IF @productType == "Plan" THEN
     Set @mobileTransfer = field(@quoteLine,"Mobile_Transfer__c")
    Set @mobileTransferDate = field(@quoteLine,"Mobile_Transfer_Date__c")
    Set @mobileStartDate = field(@quoteLine,"SBQQ__StartDate__c")
     SET @mobileProductList = CONCAT(@mobileProductList ,UpperCase(@productName),"**")
     SET @mobileProductRowset = BuildRowsetFromString(@mobileProductList,"**")
     SET @mobilePriceList = CONCAT(@mobilePriceList ,FormatNumber(@specialPrice,"#0.00") ,"**")
     SET @mobilePriceRowset = BuildRowsetFromString(@mobilePriceList,"**")
     SET @rowCountMobile = RowCount(@mobileProductRowset)
      SET @mobileProductName = @productName
      SET @mobilePrice = @specialPrice
      SET @mobileProductCodeList =  CONCAT(@mobileProductCodeList,' , ' ,@productCode)
    ENDIF
   ELSEIF @productFamily == "Gas" THEN
     IF @productCategory == "LPG" THEN
      Set @hasLPG = "True"
      SET @lpgStartDate = field(@quoteLine,"SBQQ__StartDate__c")
      SET @lpgProductName = UpperCase(@productName)
      SET @lpgServiceNameList = replace(field(@quoteLine,"Service_Name__c"),char(10),"**")
      SET @lpgServiceMeasureList = replace(field(@quoteLine,"Service_Measure__c"),char(10),"**")
      SET @lpgServiceRateList = replace(field(@quoteLine,"Service_Rate__c"),char(10),"**")
     ELSEIF @productCategory == "Reticulated" THEN
      Set @hasGas = "True"
      SET @gasProductName = UpperCase(@productName)
      SET @gasServiceNameList = replace(field(@quoteLine,"Service_Name__c"),char(10),"**")
      SET @gasServiceMeasureList = replace(field(@quoteLine,"Service_Measure__c"),char(10),"**")
      SET @gasServiceRateList = replace(field(@quoteLine,"Service_Rate__c"),char(10),"**")
     ELSEIF @productCategory=="Other" AND @productType=="Fee" THEN
      SET @gasReconnectionFeeName = UpperCase(@productName)
      SET @gasReconnectionFeePrice = FormatNumber(@specialPrice,"#0.00")
     ENDIF
    ELSEIF @productFamily == "Joining Reward" THEN
       IF @productCategory == "Incentive" AND (@productType == "Physical Good" OR  @productType == "Subscription" )THEN
          Set @hasIncentive = "True"
          SET @incentiveName = @productName
          SET @incentiveCode = @productCode
          SET @incentiveImageURL = CONCAT("https://image.communications.trustpower.co.nz/lib/fe8f13727663067f7c/m/1/",@incentiveCode,".png")
       ELSEIF @productCategory=="Incentive" AND (@productType=="Additional Credit" OR @productType=="Referral Credit" OR @productType=="Keeps Credit") THEN
          SET @creditRowsString = CONCAT(@creditRowsString,@productName,"|")
          SET @hasCredit = "True"
          IF @productCode =="JOINREW_CREDIT_150_EXIT" THEN
            SET @hasExitFeeCredit = "True"
          ENDIF
          IF @productType=="Referral Credit" THEN
            SET @hasReferralCredit = "True"
          ENDIF
       ENDIF
     ELSEIF @productFamily == "Service Product" THEN
       IF @productCategory == "Other" AND @productType == "Fee" THEN
         IF empty(@modemPostageParent1) OR @modemPostageParent1 == field(@quoteLine, "SBQQ__RequiredBy__c") THEN 
           SET @modemPostageParent1 = field(@quoteLine, "SBQQ__RequiredBy__c")
           SET @modemPostageProduct = @productName
           SET @modemPostageFee = @specialPrice
         ELSE
           SET @modemPostageParent2 = field(@quoteLine, "SBQQ__RequiredBy__c")
           SET @modemPostageProduct2 = @productName
           SET @modemPostageFee2 = @specialPrice
         ENDIF
       ENDIF
     ENDIF

Any help here would be greatly appreciated.

EDIT: Adding in the preceding script for context:


<!--%%[

/*section for personalising subject, name and intro*/

var @PreferredName, @FirstName, @PreferredNameProper, @FirstNameProper, @intro, @subject, @preheader, @introName

  Set @PreferredName = Opportunity:Primary_Contact__r:Preferred_Name__c 
  Set @FirstName = Opportunity:Primary_Contact__r:FirstName 

  IF Not Empty(@PreferredName) AND length(@PreferredName)>2 THEN
  
   Set @PreferredNameProper = Lookup('Proper Case Exception Name Mapping','ProperName','Name', @PreferredName)
   
     IF Not Empty(@PreferredNameProper) THEN
     
        Set @intro = Concat("Hi ",@PreferredNameProper,",")
        Set @introName = @PreferredNameProper
      
      ELSE
     
        Set @intro = Concat("Hi ",ProperCase(@PreferredName),",")
        Set @introName = ProperCase(@PreferredName)
      
     ENDIF
     
        ELSEIF Not Empty(@FirstName) AND length(@FirstName)>2 THEN 
          
          Set @FirstNameProper = Lookup('Proper Case Exception Name Mapping','ProperName','Name', @FirstName)
          
          IF Not Empty(@FirstNameProper) THEN
          
              Set @intro = Concat("Hi ",@FirstNameProper,",")
              Set @introName = @FirstNameProper
            
            ELSE

              Set @intro = Concat("Hi ",ProperCase(@FirstName),",")
              Set @introName = ProperCase(@FirstName)

            ENDIF
          
            ELSE 
            
             Set @intro = "Hi there,"
             
          ENDIF
          
  IF @hasChangeBundle =="True" THEN
  
    Set @subject = IIF(empty(@introName),"We're on it!",Concat(@introName,", we're on it!"))
  
  ELSEIF @acqType=="Keeps" THEN
  
    Set @subject = IIF(empty(@introName),'Thanks for staying with Trustpower',Concat(@introName,", thanks for staying with Trustpower"))
   
  ELSE
  
   Set @subject = IIF(empty(@introName),'Thanks for choosing Trustpower',Concat(@introName,", thanks for choosing Trustpower"))
   
  ENDIF

/* section for identifying the products for a customer */

var @hasPower, @hasBroadband, @hasBroadbandPhone, @hasPhoneOnly, @hasGas, @hasMobile, @hasLPG, @hasAccountCredit, @hasIncentive, @productList, @productRowset, @rows, @rowCount, @quoteId, @quoteLineRowSet, @quoteLine ,  @incentiveName , @incentiveCode, @incentiveImageURL, @productCode, @mobileProductCodeList

var @creditCheckResponse, @subscriptionTerm, @hasMedicalDependency, @hasDoubleDip, @referralCode, @FGFConsent , @offerTypeId, @offerType, @exitFee
var @productFamily, @productType , @hasUFB, @hasDSL,@hasWBB, @broadbandProductName, @broadbandPrice, @otherBroadbandName, @otherBroadbandPrice, @specialPrice, @phoneProductName, @phoneProductPrice, @CopperQuoteLineId, @UFBQuoteLineId, @WBBQuoteLineId

var @modemPostageFee, @modemPostageProduct, @modemPostageParent1, @modemPostageParent2, @modemPostageProduct2, @modemPostageFee2, @favNumberList, @favNumberRowset, @extraAddOnsList, @extraAddOnsRowset, @extraAddOnsPriceList, @extraAddOnsPriceRowset, @hasFavNumber, @rowCountFavNumber, @rowCountAddOns, @hasAddOn, @hasAddOn2, @currentConnectionType , @currentProvider, @failedCall

    Set @rowCountFavNumber = 0
    Set @rowCountAddOns = 0

var @powerServiceNameList, @powerServiceMeasureList, @powerServiceRateList, @powerServiceRateRowset, @powerServiceMeasureRowset, @powerServiceNameRowset, @rowCountElecCharge, @elecReconnectionFeeName, @electReconnectionFeePrice

var @lpgServiceNameList, @lpgServiceMeasureList, @lpgServiceRateList, @lpgServiceRateRowset, @lpgServiceMeasureRowset, @lpgServiceNameRowset, @rowCountLPGCharge, @urgentLPGDelivery

var @gasServiceNameList, @gasServiceMeasureList, @gasServiceRateList, @gasServiceRateRowset, @gasServiceMeasureRowset, @gasServiceNameRowset, @gasReconnectionFeeName, @gasReconnectionFeePrice, @rowCountGasCharge

var @youChoose, @12MHP, @flexiPlan , @mobileTransfer, @mobileTransferDate, @mobileStartDate, @lpgStartDate, @avServiceId, @moveInTransferStatus

var @recordRows, @avRecordTypeId, @avServRows

var @mobileProductList, @mobilePriceList, @mobileProductRowset, @mobilePriceRowset, @rowCountMobile

var @addOnParent1QuoteLineId, @addOnParent2QuoteLineId, @hasFavNumber2, @favNumberList2 , @favNumberRowset2, @rowCountFavNumber2, @extraAddOnsList2, @extraAddOnsRowset2, @extraAddOnsPriceList2, @extraAddOnsPriceRowset2, @rowCountAddOns2 , @quoteRow, @quoteRowset

/*WM API Variable setting*/

  var @customerEmail, @customerNumber
  Set @customerNumber = Opportunity:Primary_Contact__r:Customer_Number__c
  Set @customerEmail = emailaddr
  Set @youChoose = "You Choose"
  Set @12MHP = "12MHP"
  Set @flexiPlan = "Flexi Plan"
  Set @rowCountElecCharge = 0
  Set @rowCountLPGCharge = 0
  Set @rowCountGasCharge = 0
  Set @rowCountAddOns = 0
  Set @rowCountAddOns2 = 0
  
/*Available Services Trade Participant ID*/

  var @serviceType, @traderParticipant, @providerDisclaimer
  
    Set @serviceType = Opportunity:Electricity_ICP_Number__r:Service_Type__c
    Set @traderParticipant = Opportunity:Electricity_ICP_Number__r:Trader_Participant_Identifier__c
    
    IF (@serivceType == "Electricity" AND (@traderParticipant == "PPPP" OR @traderParticipant == "PUNZ" OR @traderParticipant == "CPPL")) THEN
    
      Set @providerDisclaimer = "true"
      
    ENDIF

/*Pull the Location*/

  var @opptyLocation, @locationRows, @tier, @highestRankedArea

  Set @opptyLocation = Opportunity:Location__r:Id
  set @tier = Opportunity:Location__r:Tier__c
  set @locationName = Opportunity:Location__r:Name
  set @highestRankedArea = Opportunity:Location__r:Highest_Ranked_Area__c 
  Set @quoteId = Opportunity:SBQQ__PrimaryQuote__r:Id
  Set @creditCheckResponse = Opportunity:Credit_Check_Response__c
  Set @subscriptionTerm = Opportunity:SBQQ__PrimaryQuote__r:Contract_Term__c
  Set @exitFee = Opportunity:SBQQ__PrimaryQuote__r:Exit_Fee__c
  Set @offerTypeId = Opportunity:SBQQ__PrimaryQuote__r:Offer_Type__c

  IF empty(@exitFee) OR empty(@offerTypeId) OR empty(@subscriptionTerm) THEN
   
   set @quoteRowSet = RetrieveSalesforceObjects(
     "SBQQ__Quote__c",
     "Offer_Type__c,Exit_Fee__c,Contract_Term__c",
     "Id", "=", @quoteId )
     
     IF RowCount(@quoteRowSet) >= 1 THEN
     
       set @quoteRow = row(@quoteRowSet, 1)
       SET @exitFee = field(@quoteRow,"Exit_Fee__c")
       SET @offerTypeId = field(@quoteRow,"Offer_Type__c")
       SET @subscriptionTerm = field(@quoteRow,"Contract_Term__c")
       
     ENDIF
     
  ENDIF
  
  IF not empty(@subscriptionTerm) AND  @subscriptionTerm !="No Term" THEN
  
    SET @subscriptionTerm = FormatNumber(@subscriptionTerm,"g")
   
  ENDIF
  
  IF not empty(@exitFee) THEN
  
    SET @exitFee = FormatCurrency(@exitFee, "en-US",0)
   
  ENDIF
  
  IF not empty (@offerTypeId) THEN
  
    SET @offerType = Lookup("Offer_Type__c_Salesforce","Offer_Type__c","Id",@offerTypeId) 
   
  ENDIF

Set @hasMedicalDependency = Opportunity:Account:HasMedicalDependent__c
Set @referralCode = Opportunity:Primary_Contact__r:FGF_Referral_Code__c
Set @FGFConsent = Opportunity:SBQQ__PrimaryQuote__r:FGF_Consent__c

IF (Opportunity:ChannelSource__c == "D2D" OR Opportunity:ChannelSource__c == "Outbound") THEN

 Set @unsolicitedSale = "True"

ENDIF

var @fix

/*section improvements by Adam - STARTS*/

]%% -->
1

Did you intend to check for a rowcount greater than 0 or 1? Since you didn't include the end of your for-loop and the end of the preceding conditional, I can't tell if you doing something different in that situation.

I would definitely use a @debug flag and some conditional output before any conditionals to ensure you're getting what you expect.

One other glaring thing -- you need to initialize any flag values every iteration. You'll get unintended, accumulating output if they never get reset.

Also, I try to stay away from AMPscript's pseudo-Boolean data type and just opt for 1 or 0. I find it less ambiguous and less to type.

%%[

var @debug
set @debug = 1

set @quoteLineRowSet = RetrieveSalesforceObjects(
   "SBQQ__QuoteLine__c",
"Id,SBQQ__Product__c,Product_Category__c,SBQQ__ProductFamily__c,Product_Commercial_Name__c,Product_Type__c,SBQQ__ProductCode__c,Current_Connection_Type__c,Current_Provider_Name__c,Mobile_Transfer_Date__c,SBQQ__StartDate__c,SBQQ__SpecialPrice__c,FavouriteCountry__c,Favourite_Phone_Number__c,Service_Rate__c,Service_Name__c,Service_Measure__c,Mobile_Transfer__c,SBQQ__RequiredBy__c,Incentive_Level__c",
   "SBQQ__Quote__c", "=", @quoteId,"SBQQ__Quantity__c",">=","1" )

set @rowcount = RowCount(@quoteLineRowSet)

if @debug == 1 then
  output(concat("<br>quoteId", @quoteId))
  output(concat("<br>rowcount", @rowcount))
endif

if @rowcount > 1 then /* if multiple records are found then loop through*/

 for @i = 1 to @rowcount do

   set @hasAddOn = 0
   set @hasAddOn2 = 0
   set @hasBroadband = 0
   set @hasBroadbandPhone = 0
   set @hasCredit = 0
   set @hasDSL = 0
   set @hasExitFeeCredit = 0
   set @hasFavCountry = 0
   set @hasFavCountry2 = 0
   set @hasFavNumber = 0
   set @hasFavNumber2 = 0
   set @hasFibreMax = 0
   set @hasGas = 0
   set @hasIncentive = 0
   set @hasLPG = 0
   set @hasMobile = 0
   set @hasPhoneOnly = 0
   set @hasPower = 0
   set @hasReferralCredit = 0
   set @hasUFB = 0
   set @hasWBB = 0

   set @quoteLine = row(@quoteLineRowSet, @i)

   SET @productFamily = field(@quoteLine,"SBQQ__ProductFamily__c")
   SET @productType = field(@quoteLine,"Product_Type__c")
   SET @productCategory = field(@quoteLine,"Product_Category__c")
   SET @productName = field(@quoteLine,"Product_Commercial_Name__c")
   SET @specialPrice = field(@quoteLine,"SBQQ__SpecialPrice__c")
   SET @productCode = field(@quoteLine,"SBQQ__ProductCode__c")
   SET @incentiveTier = field(@quoteLine,"Incentive_Level__c")

   if @debug == 1 then
     output(concat("<br>"))
     output(concat("<br>i: ", @i))
     output(concat("<br>productFamily: ", @productFamily))
     output(concat("<br>productType: ", @productType))
     output(concat("<br>productCategory: ", @productCategory))
     output(concat("<br>productName: ", @productName))
     output(concat("<br>specialPrice: ", @specialPrice))
     output(concat("<br>productCode: ", @productCode))
     output(concat("<br>incentiveTier: ", @incentiveTier))
   endif

   IF @productFamily == "Power" THEN

      Set @hasPower = 1

      IF @productCategory =="Electricity" THEN

       SET @elecProductName = CONCAT(UpperCase(@productType)," POWER RATE")
       SET @powerServiceNameList = replace(field(@quoteLine,"Service_Name__c"),char(10),"**")
       SET @powerServiceMeasureList = replace(field(@quoteLine,"Service_Measure__c"),char(10),"**")
       SET @powerServiceRateList = replace(field(@quoteLine,"Service_Rate__c"),char(10),"**")

      ELSEIF @productCategory=="Other" AND @productType=="Fee" THEN

         SET @elecReconnectionFeeName = UpperCase(@productName)
         SET @electReconnectionFeePrice = FormatNumber(@specialPrice,"#0.00")

      ENDIF

   ELSEIF @productFamily == "Broadband" THEN

     SET @currentConnectionType = field(@quoteLine, "Current_Connection_Type__c")
     SET @currentProvider = field(@quoteLine, "Current_Provider_Name__c")

     IF indexof(@productName,"FibreMax") > 0 and @productCategory == "Fibre" and @productType != "Phone" THEN

        Set @hasUFB = 1
        SET @hasFibreMax = 1
        SET @fibreMaxTest = "Test content"
        SET @broadbandProductName = UpperCase(@productName)
        SET @broadbandPrice = FormatNumber(@specialPrice,"#0.00")
        SET @UFBQuoteLineId =field(@quoteLine,"Id")

     ELSEIF indexof(@productCategory,"100/20") < 0 and @productCategory == "Fibre" and @productType != "Phone" THEN

        Set @hasUFB = 1
        SET @hasFibreMax = 1
        SET @broadbandProductName = UpperCase(@productName)
        SET @broadbandPrice = FormatNumber(@specialPrice,"#0.00")
        SET @UFBQuoteLineId =field(@quoteLine,"Id")

     ELSEIF @productCategory == "Copper" and @productType != "Phone" THEN

        Set @hasDSL = 1
        SET @otherBroadbandName = UpperCase(@productName)
        SET @otherBroadbandPrice = FormatNumber(@specialPrice,"#0.00")
        SET @CopperQuoteLineId =field(@quoteLine,"Id")

     ELSEIF @productCategory == "Wireless" and @productType != "Phone" THEN

        Set @hasWBB = 1
        SET @otherBroadbandName = UpperCase(@productName)
        SET @otherBroadbandPrice = FormatNumber(@specialPrice,"#0.00")
        SET @WBBQuoteLineId =field(@quoteLine,"Id")

     ELSEIF @productCategory =="Add-on" THEN

      IF empty (@addOnParent1QuoteLineId) OR  @addOnParent1QuoteLineId == field(@quoteLine, "SBQQ__RequiredBy__c") THEN

        SET @addOnParent1QuoteLineId = field(@quoteLine, "SBQQ__RequiredBy__c")
        SET @hasAddOn = 1

        IF @productType=="Favourite" THEN

         IF @productName=="Favourite Number" THEN

           SET @hasFavNumber = 1
           SET @favNumberList = CONCAT(@favNumberList ,field(@quoteLine,"Favourite_Phone_Number__c"),"**")
           SET @favNumberRowset = BuildRowsetFromString(@favNumberList,"**")
           SET @rowCountFavNumber = RowCount(@favNumberRowset)

         ELSEIF @productName=="Favourite Country" THEN

            SET @hasFavCountry = 1
            SET @favCountryList = CONCAT(@favCountryList ,field(@quoteLine,"FavouriteCountry__c"),"**")
            SET @favCountryRowset = BuildRowsetFromString(@favCountryList,"**")
            SET @rowCountFavCountry = RowCount(@favCountryRowset)

         ENDIF

        ELSE

          SET @extraAddOnsList = CONCAT(@extraAddOnsList ,UpperCase(@productName),"**")
          SET @extraAddOnsRowset = BuildRowsetFromString(@extraAddOnsList,"**")
          SET @extraAddOnsPriceList = CONCAT(@extraAddOnsPriceList , FormatNumber(@specialPrice,"N"), "**")
          SET @extraAddOnsPriceRowset = BuildRowsetFromString(@extraAddOnsPriceList,"**")
          SET @rowCountAddOns = RowCount(@extraAddOnsRowset)

        ENDIF

      ELSE

       SET @hasAddOn2 = 1

       IF @productType=="Favourite" THEN

         IF @productName=="Favourite Number" THEN

           SET @hasFavNumber2 = 1
           SET @favNumberList2 = CONCAT(@favNumberList2 ,field(@quoteLine,"Favourite_Phone_Number__c"),"**")
           SET @favNumberRowset2 = BuildRowsetFromString(@favNumberList2,"**")
           SET @rowCountFavNumber2 = RowCount(@favNumberRowset2)

         ELSEIF @productName=="Favourite Country" THEN

          SET @hasFavCountry2 = 1
          SET @favCountryList2 = CONCAT(@favCountryList2 ,field(@quoteLine,"FavouriteCountry__c"),"**")
          SET @favCountryRowset2 = BuildRowsetFromString(@favCountryList2,"**")
          SET @rowCountFavCountry2 = RowCount(@favCountryRowset2)

         ENDIF

        ELSE
          SET @extraAddOnsList2 = CONCAT(@extraAddOnsList2 ,UpperCase(@productName),"**")
          SET @extraAddOnsRowset2 = BuildRowsetFromString(@extraAddOnsList2,"**")
          SET @extraAddOnsPriceList2 = CONCAT(@extraAddOnsPriceList2 ,FormatNumber(@specialPrice,"N"),"**")
          SET @extraAddOnsPriceRowset2 = BuildRowsetFromString(@extraAddOnsPriceList2,"**")
          SET @rowCountAddOns2 = RowCount(@extraAddOnsRowset2)

        ENDIF

      ENDIF

     ENDIF

     IF @productType == "Naked" THEN

        Set @hasBroadband = 1

     ELSEIF @productType == "Clothed" THEN

        Set @hasBroadbandPhone = 1

     ELSEIF @productType == "Phone" THEN

        Set @hasPhoneOnly = 1

        SET @phoneProductName = UpperCase(@productName)
        SET @phoneProductPrice = FormatNumber(@specialPrice,"#0.00")

     ENDIF

   ELSEIF @productFamily == "Mobile" THEN

      Set @hasMobile = 1

      IF @productType == "Plan" THEN

        Set @mobileTransfer = field(@quoteLine,"Mobile_Transfer__c")
        Set @mobileTransferDate = field(@quoteLine,"Mobile_Transfer_Date__c")
        Set @mobileStartDate = field(@quoteLine,"SBQQ__StartDate__c")
        SET @mobileProductList = CONCAT(@mobileProductList ,UpperCase(@productName),"**")
        SET @mobileProductRowset = BuildRowsetFromString(@mobileProductList,"**")
        SET @mobilePriceList = CONCAT(@mobilePriceList ,FormatNumber(@specialPrice,"#0.00") ,"**")
        SET @mobilePriceRowset = BuildRowsetFromString(@mobilePriceList,"**")
        SET @rowCountMobile = RowCount(@mobileProductRowset)
        SET @mobileProductName = @productName
        SET @mobilePrice = @specialPrice
        SET @mobileProductCodeList =  CONCAT(@mobileProductCodeList,' , ' , @productCode)

      ENDIF

   ELSEIF @productFamily == "Gas" THEN

     IF @productCategory == "LPG" THEN

        Set @hasLPG = 1
        SET @lpgStartDate = field(@quoteLine,"SBQQ__StartDate__c")
        SET @lpgProductName = UpperCase(@productName)
        SET @lpgServiceNameList = replace(field(@quoteLine,"Service_Name__c"),char(10),"**")
        SET @lpgServiceMeasureList = replace(field(@quoteLine,"Service_Measure__c"),char(10),"**")
        SET @lpgServiceRateList = replace(field(@quoteLine,"Service_Rate__c"),char(10),"**")

     ELSEIF @productCategory == "Reticulated" THEN

        Set @hasGas = 1
        SET @gasProductName = UpperCase(@productName)
        SET @gasServiceNameList = replace(field(@quoteLine,"Service_Name__c"),char(10),"**")
        SET @gasServiceMeasureList = replace(field(@quoteLine,"Service_Measure__c"),char(10),"**")
        SET @gasServiceRateList = replace(field(@quoteLine,"Service_Rate__c"),char(10),"**")

     ELSEIF @productCategory=="Other" AND @productType=="Fee" THEN

        SET @gasReconnectionFeeName = UpperCase(@productName)
        SET @gasReconnectionFeePrice = FormatNumber(@specialPrice,"#0.00")

     ENDIF

   ELSEIF @productFamily == "Joining Reward" THEN

       IF @productCategory == "Incentive" AND (@productType == "Physical Good" OR  @productType == "Subscription" )THEN

          Set @hasIncentive = 1
          SET @incentiveName = @productName
          SET @incentiveCode = @productCode
          SET @incentiveImageURL = CONCAT("https://image.communications.trustpower.co.nz/lib/fe8f13727663067f7c/m/1/", @incentiveCode,".png")

       ELSEIF @productCategory=="Incentive" AND (@productType=="Additional Credit" OR @productType=="Referral Credit" OR @productType=="Keeps Credit") THEN

          SET @creditRowsString = CONCAT(@creditRowsString, @productName,"|")
          SET @hasCredit = 1

          IF @productCode =="JOINREW_CREDIT_150_EXIT" THEN
            SET @hasExitFeeCredit = 1
          ENDIF

          IF @productType=="Referral Credit" THEN
            SET @hasReferralCredit = 1
          ENDIF

       ENDIF

   ELSEIF @productFamily == "Service Product" THEN

       IF @productCategory == "Other" AND @productType == "Fee" THEN

           IF empty(@modemPostageParent1) OR @modemPostageParent1 == field(@quoteLine, "SBQQ__RequiredBy__c") THEN
             SET @modemPostageParent1 = field(@quoteLine, "SBQQ__RequiredBy__c")
             SET @modemPostageProduct = @productName
             SET @modemPostageFee = @specialPrice
           ELSE
             SET @modemPostageParent2 = field(@quoteLine, "SBQQ__RequiredBy__c")
             SET @modemPostageProduct2 = @productName
             SET @modemPostageFee2 = @specialPrice
           ENDIF

       ENDIF

   ENDIF

   if @debug == 1 then

      output(concat("<br>hasAddOn: ", @hasAddOn))
      output(concat("<br>hasAddOn2: ", @hasAddOn2))
      output(concat("<br>hasBroadband: ", @hasBroadband))
      output(concat("<br>hasBroadbandPhone: ", @hasBroadbandPhone))
      output(concat("<br>hasCredit: ", @hasCredit))
      output(concat("<br>hasDSL: ", @hasDSL))
      output(concat("<br>hasExitFeeCredit: ", @hasExitFeeCredit))
      output(concat("<br>hasFavCountry: ", @hasFavCountry))
      output(concat("<br>hasFavCountry2: ", @hasFavCountry2))
      output(concat("<br>hasFavNumber: ", @hasFavNumber))
      output(concat("<br>hasFavNumber2: ", @hasFavNumber2))
      output(concat("<br>hasFibreMax: ", @hasFibreMax))
      output(concat("<br>hasGas: ", @hasGas))
      output(concat("<br>hasIncentive: ", @hasIncentive))
      output(concat("<br>hasLPG: ", @hasLPG))
      output(concat("<br>hasMobile: ", @hasMobile))
      output(concat("<br>hasPhoneOnly: ", @hasPhoneOnly))
      output(concat("<br>hasPower: ", @hasPower))
      output(concat("<br>hasReferralCredit: ", @hasReferralCredit))
      output(concat("<br>hasUFB: ", @hasUFB))
      output(concat("<br>hasWBB: ", @hasWBB))


   endif

]%%
2
  • Hi Adam, first off, it's a privilege to have your help here - I really appreciate it and apologies you had to run through my poorly formatted code. I have added in the preceding conditions however there is plenty that follows after the above, which I haven't been able to include (it tips over the character limits). I intended on a rowcount greater than 0 but reviewing my code, I noticed I used an unintentional '<' operator. It should read indexof(@productCategory,"100/20") > 0 – Benjamin Penketh Nov 16 '20 at 9:01
  • Thank you for all your advice above, Adam. I really appreciate the debug script and the binary replacement for pseudo-Boolean data type - it's so much cleaner. Now to go through and update all of our emails to use 1 and 0s :) – Benjamin Penketh Nov 16 '20 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.