• Sebastian Morris
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello,

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:page>
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!