I have a visualforce page that we want to use to look up campaign members. The user is supposed to select a campaign, and then get an input field to type in member numbers. Those member numbers are then searched for in the campaignmember object. If found, that status needs to be displayed, and then the user can type in another one.
For some reason that I can't figure out is that the variables allowScan
and scanStatus
never get the value assigned in checkScanValue()
that I would expect. I know the function is called, because I can see the DEBUG message in the logs.
VisualForce page:
<apex:page docType="html-5.0" controller="ElectionCampaign_Scan" showHeader="false">
<apex:form id="TopPageBlock">
<apex:pageBlock >
<apex:pageBlockSection id="CampaignSelection" columns="2">
<apex:outputLabel value="Campaign" />
<apex:selectList size="1" value="{!campaignSelectedId}">
<apex:selectOptions value="{!campaignOptions}"/>
<apex:actionSupport event="onchange" action="{!checkCampaignValue}" />
</apex:selectList>
</apex:pageBlockSection>
<apex:pageBlockSection id="CampaignInfo" columns="1">
<apex:outputField value="{!campaignSelected.Name}"/>
<apex:outputField value="{!campaignSelected.Type}"/>
<apex:outputField value="{!campaignSelected.Primary_Theme__c}"/>
<apex:outputField value="{!campaignSelected.Secondary_Theme__c}"/>
<apex:outputLabel value="{!campaignMemberValue}" />
<apex:outputLabel value="{!scanStatus}" />
<apex:outputLabel value="{!allowScan}" />
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!campaignSelected.Name <> ''}" id="CampaignMemberScan">
<apex:pageBlockSection id="CampaignMemberScanValue" columns="1">
<apex:outputLabel value="Member ID:" />
<apex:input type="text" value="{!campaignMemberValue}" rendered="{!allowScan}" >
<apex:actionSupport event="onchange" action="{!checkScanValue}" reRender="CampaignMemberScanStatus"/>
</apex:input>
</apex:pageBlockSection>
<apex:pageBlockSection id="CampaignMemberScanStatus" columns="1">
<apex:outputText rendered="{! !allowScan}" id="timeout">
<p>
This should show sometime!
</p>
<script>
//setTimeout(CallApexClear(), 10000);
</script>
</apex:outputText>
<apex:outputText value="{0}: {1} {2}" rendered="{!if(allowScan==true,true,true)}" >
<apex:param value="{!campaignMemberId}" />
<apex:param value="{!campaignMemberName}" />
<apex:param value="{!campaignMemberStatus}" />
</apex:outputText>
</apex:pageBlockSection>
<apex:messages />
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class ElectionCampaign_Scan
{
public Id campaignSelectedId { get;set; }
public Campaign campaignSelected { get;set; }
public List<SelectOption> campaignOptions { get;set; }
public string campaignMemberValue { get;set; }
public string campaignMemberName { get;set; }
public string campaignMemberID { get;set; }
public string campaignMemberStatus { get;set; }
public string scanStatus { get;set; }
public boolean allowScan { get; set; }
public boolean isSandbox { get; set; }
public ElectionCampaign_Scan()
{
System.debug('ElectionCampaign_Scan');
isSandbox = [SELECT Id, IsSandbox FROM Organization LIMIT 1].IsSandbox;
List<Campaign> Campaigns = [SELECT Id, Name from Campaign WHERE Primary_Theme__c LIKE '%Election%' AND IsActive = True];
CampaignOptions = new list<SelectOption>();
CampaignOptions.add(new SelectOption('',''));
for (Campaign c : Campaigns)
{
CampaignOptions.add(new SelectOption(c.id,c.Name));
}
allowScan = true;
}
public void checkCampaignValue()
{
System.debug('checkCampaignValue');
List<Campaign> campaigns = [SELECT Id, Name, Type, SubType__c, Category__c, Primary_Theme__c, Secondary_Theme__c, Status, StartDate, EndDate FROM Campaign WHERE Id = :campaignSelectedId LIMIT 1];
if( campaigns.isEmpty() == false )
{
campaignSelected = campaigns[0];
}
}
public void checkScanValue()
{
scanStatus = '';
allowScan = false;
System.debug('checkScanValue');
List<CampaignMember> campaignMembers = [SELECT Id, Name, Status FROM CampaignMember WHERE Contact.Unionware_Calculated_Identifier__c = :campaignMemberValue AND CampaignId = :campaignSelected.Id LIMIT 1];
if( campaignMembers.isEmpty() == true )
{
campaignMemberID = campaignMemberValue;
campaignMemberName = '';
campaignMemberStatus = 'Not part of the campaign';
scanStatus = 'Not part of the campaign';
}
else
{
campaignMemberID = campaignMemberValue;
campaignMemberName = campaignMembers[0].Name;
campaignMemberStatus = campaignMembers[0].status;
if( campaignMembers[0].status == 'Send' )
{
scanStatus = 'Send';
}
else
{
scanStatus = 'Already scanned';
}
}
}
}
Thanks!