0

I have a visualforce page on the Case object that lists out assets with accessories related to the case. I have an input field where a setup technician types in the asset serial number along with the accessory serial numbers. After the serial numbers are entered the technician will check a "setup complete" checkbox and click the "Update" button which updates the serial numbers on the asset and checks the checkbox on the case. The issue I am running into is when the technician clicks the "update" button a verification needs to take place looping through the asset and accessories comparing the serial number that the setup technician entered (Serial_Number_Service_Setup__c) and the serial number that was entered when the equipment was pulled (Serial_Number_Procurement__c). If the serial numbers match then the "Serial_Number_Service_Setup__c" field needs to update on the asset with the serial number. If the serial numbers do not match then a screen alert needs to pop up saying the serial number did not match and to re-enter the serial number. After the serial number is entered again then the "Serial_Number_Service_Setup__c" field on the asset needs to update with the serial number that the technician entered. As of right now the the checkbox is being checked on the case and the serial number is being updated on the asset when the "update" button is clicked, but I can't seem to figure out how to get the serial number verification to work. Unfortionatly I only know a little bit when it comes to apex and javascript.

Here is my visual for page:

<apex:page standardController="Case" extensions="pullEquipmentUpdateAssetClass">     
<p></p>
<apex:form > 
    <apex:pageblock id="Assets">

        <apex:pageBlockSection columns="1"> <!-- to allow the apex:input to show the label -->
            <apex:pageBlockTable value="{!Case.Assets__r}" var="asset">
                <apex:column value="{!asset.Product_Code_Display__c}"/>
                <apex:column value="{!asset.Product_Description_Display__c}"/> 
                <apex:column value="{!asset.Delivery_Address__c}"/>
                <apex:column id="procurementSerialNumber" value="{!asset.Serial_Number_Procurement__c}"/>
                <apex:column headerValue="{!$ObjectType.Asset.fields.Serial_Number_Service_Setup__c.label}"><!-- to take the label dynamically -->
                    <apex:inputText id="setupSerialNumber" value="{!asset.Serial_Number_Service_Setup__c}" />
                </apex:column>
                <apex:column value="{!asset.Serialized__c}"/>
            </apex:pageBlockTable>

            <apex:inputCheckbox value="{!Case.Setup_Complete__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockButtons location="bottom">                
            <apex:commandButton id="checkSerial"  value="Update" action="{!saveSerialIdNumber}"/>
        </apex:pageBlockButtons>
    </apex:pageblock>
</apex:form>

<script>

document.getElementById("checkSerial").onclick = function()
{checkSerialNumber()};
 function checkSerialNumber(){
    var serialNumberSetup = document.getElementById(setupSerialNumber).value;
    var serialNumberProcurement = document.getElementById(procurementSerialNumber).value;
     document.getElementById("checkSerial").innerHTML =
         for (var i = 0; i < serialNumberSetup.length; i++){
        if(serialNumberSetup != serialNumberProcurement){
                alert('Serial numbers do not match');
            }

</script>

Apex Class:

public class setupEquipmentUpdateAssetClass {

private ApexPages.StandardController controller;

//Constructor 
public setupEquipmentUpdateAssetClass(ApexPages.StandardController controller) {
    this.controller = controller;
}

public void saveSerialIdNumber() {

    update ((Case) controller.getRecord()).Assets__r;


    controller.save();
}

}

Any help I could get on this would be greatly appreciated!

1
0

After a couple weeks of trial and error I found a solution.

VisualForce:

e<apex:page standardController="Case" extensions="pullEquipmentUpdateAssetClass" id="thePage"> 
<style>
.procurementSerialNumber{
    }
.setupSerialNumber {
    }
.setupModel {
    }
</style>
<p></p>
<apex:form id="theForm"> 
    <apex:pageblock id="Assets">

        <apex:pageBlockSection id="pbs" columns="1"> <!-- to allow the apex:input to show the label -->
            <apex:pageBlockTable id="pbt" value="{!Case.Assets__r}" var="asset">
                <!--<apex:column styleClass="setupModel" value="{!asset.Product_Code_Display__c}"/>-->
                
                <apex:column headerValue="{!$ObjectType.Asset.fields.Product_Code_Display__c.label}"><!-- to take the label dynamically -->

                    <apex:inputText disabled="true" styleClass="setupModel" value="{!asset.Product_Code_Display__c}"  />
                </apex:column>
                
                <apex:column value="{!asset.Product_Description_Display__c}"/> 
                <apex:column value="{!asset.Delivery_Address__c}"/>

                <!--<apex:column styleClass="procurementSerialNumber" value="{!asset.Serial_Number_Procurement__c}"/>-->
               <apex:column headerValue="{!$ObjectType.Asset.fields.Serial_Number_Procurement__c.label}"><!-- to take the label dynamically -->

                    <apex:inputText disabled="true" styleClass="procurementSerialNumber" value="{!asset.Serial_Number_Procurement__c}"  />
                </apex:column>
                
                <apex:column headerValue="{!$ObjectType.Asset.fields.Serial_Number_Service_Setup__c.label}"><!-- to take the label dynamically -->

                    <apex:inputText onchange="getSetupSerialNumbers(this); return false;" styleClass="setupSerialNumber" value="{!asset.Serial_Number_Service_Setup__c}"  />
                </apex:column>
                <apex:column value="{!asset.Serialized__c}"/>
            </apex:pageBlockTable>

            <apex:inputCheckbox value="{!Case.Setup_Complete__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockButtons location="bottom">                
            <apex:commandButton value="Update" action="{!saveSerialIdNumber}" />
        </apex:pageBlockButtons>
    </apex:pageblock>
</apex:form>

</apex:page>

Javascript:

<script>
var getSerialNumberSetup;
var getSerialNumberProcurement;
var setupSerialNumber;
var procurementSerialNumber;
var setupArray = [];
var ProcurementArray = [];
var getSetupModel;
var setupModelArray = [];
var setupModel;

function getSetupSerialNumbers(){ getSerialNumberSetup = document.querySelectorAll(".setupSerialNumber");

    for(var i = 0; i < getSerialNumberSetup.length; i++){
        //console.log('get ' + getSerialNumberSetup[i]);
        setupSerialNumber = getSerialNumberSetup[i].value;
        //console.log('setup ' + setupSerialNumber);
        
        if(setupSerialNumber != null){
            setupArray.push(setupSerialNumber);
            }
        }
console.log('setup array ' + setupArray);

getSerialNumberProcurement = document.querySelectorAll(".procurementSerialNumber");
    
    for(var x = 0; x < getSerialNumberProcurement.length; x++){
        //console.log('get ' + getSerialNumberProcurement[x]);
            procurementSerialNumber = getSerialNumberProcurement[x].value;
        //  console.log('procurement ' + procurementSerialNumber);
        
        if(procurementSerialNumber != null){
            ProcurementArray.push(procurementSerialNumber);
            }
        }
console.log('procurement array ' + ProcurementArray);  

 getSetupModel = document.querySelectorAll(".setupModel");

for(m = 0; m < getSetupModel.length; m++){
    setupModel = getSetupModel[m].value;
    //console.log('model ' + setupModel);
    if(setupModel != null){
        setupModelArray.push(setupModel);    
    }   
}
console.log('model array ' + setupModelArray);

for(y = 0; y < setupArray.length; y++){
    if(setupArray[y] != ProcurementArray[y]){
    alert('serial numbers do not match for model ' + setupModelArray[y] + '. setup: ' + setupArray[y] + ' procurement: ' + ProcurementArray[y]);   
    }else{
    alert('serial numbers are a freaking match for model ' + setupModelArray[y] + '. setup: ' + setupArray[y] + ' procurement: ' + ProcurementArray[y]);    
 }
 }

}

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.