Avatar

Correct answer by
Employee Advisor

x

var rcpObj = nms.recipient.load(ctx.recipient.@id);
var rcpXml = {recipient: {_key: "id", id: rcpObj.id}}

if (!rcpObj.doubleOptin) { 
 
        nms.subscription.Unsubscribe('SVC_DO_CAZ', rcpXml);
        nms.subscription.Unsubscribe('SVC_DO_SCH',  rcpXml);   
      
        rcpObj.doubleOptin=1
        rcpObj.save();
             
          /**********************************/
               
          if (rcpObj.doubleOptin == 1) 
      
			{     
                  
                  if (rcpObj.origin == "ESG") {
                  
                    if (rcpObj.lawfulBasis == 2 || rcpObj.lawfulBasis == 3) {
                      nms.subscription.Subscribe('SVC52',  rcpXml, false);                      
                    }
                                    
                    var goal = sqlSelect("latest,@id:string",
                                         "SELECT MAX(iGoalsId) as xyz FROM CusGoals WHERE biRecipientId='"+parseInt(ctx.recipient.@id)+"' "); //get latest goalId
                    
                    xtk.workflow.PostEvent("WKF_ESG", "signal", "", <variables recipientId={parseInt(ctx.recipient.@id)} prospect="1" goalId={parseInt(goal.latest.@id)} />, false);   //start delivery workflow and send variables                      
                    logInfo("Recipient Verified: "+rcpObj.email+" "+parseInt(goal.latest.@id)+" "+parseInt(ctx.recipient.@id));                                                     
                
                  } else if(rcpObj.origin == "Carbon") {
                    //dosomething
                  }
          
			}
      
          /*********************************/            

} else if (rcpObj.doubleOptin) {
   logInfo("Recipient already optedin: "+rcpObj.email+" "+parseInt(ctx.recipient.@id));
}

My solution was to enhance my double opt-in logic, here is a free snippet in case it may help others with their tasks

View solution in original post