function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Luke Higgins 23Luke Higgins 23 

updateRecord not working on conditional input text

I have an lightning-input text box and I'm trying to add the input value to one of multiple fields using updateRecord of the uiRecordApi, depending on if it has a value already or not. Any idea on what the issue is?
HTML:
<template>
<lightning-card title="enterTagsLwc" icon-name="standard:contact">
    <div class="acc-container">
            <div class="slds-m-around_large slds-is-relative">
                <!--spinner to go while process is happening-->
                    <div if:true={isLoaded} class="slds-spinner_container">
                        <lightning-spinner
                            alternative-text="Loading...">
                        </lightning-spinner>
                    </div> 
                </div>
                <div class="slds-grid slds-gutters">
                    <div class="slds-col slds-size_3-of-4 ">
                        <c-enter-tags-search label-name="Enter Tags" class="slds-m-bottom_x-small" onselected={handleSelected}></c-enter-tags-search > 
                    </div>
                    <div class="slds-col slds-size_1-of-4 slds-p-top_x-large">
                        <lightning-button label="Add Tag" variant="brand" onclick={updateContact}></lightning-button>
                    </div>
                </div>
    </div>
</lightning-card>
</template>

JS:
import { LightningElement, api, wire, track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { getRecord, updateRecord, generateRecordInputForUpdate, getFieldValue,  } from 'lightning/uiRecordApi';
import TAG from '@salesforce/schema/Contact.Tags__c';
import TAG1 from '@salesforce/schema/Contact.Tags1__c';
import TAG2 from '@salesforce/schema/Contact.Tags2__c';
import TAG3 from '@salesforce/schema/Contact.Tags3__c';
import TAG4 from '@salesforce/schema/Contact.Tags4__c';

const FIELDS = [TAG, TAG1, TAG2, TAG3, TAG4];
export default class EnterTagsLwc extends LightningElement {
@api recordId;
@track isLoaded = false;
@track contactId;
contact;
@track tagName;
@track tags;
@track tags1;
@track tags2;
@track tags3;
@track tags4;
@track inputVal;

@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
wiredRecord({ error, data }) {
    if (error) {
        let message = 'Unknown error';
        if (Array.isArray(error)) {
            message = error.map(e => e.message).join(', ');
        } else if (typeof error.message === 'string') {
            message = error.message;
        }
        this.dispatchEvent(
            new ShowToastEvent({
                title: 'Error loading contact',
                message,
                variant: 'error',
            }),
        );
    } else if (data) {
        this.contact = data;
        this.tags = this.contact.fields.Tags__c.value;
        this.tags1 = this.contact.fields.Tags1__c.value;
        this.tags2 = this.contact.fields.Tags2__c.value;
        this.tags3 = this.contact.fields.Tags3__c.value;
        this.tags4 = this.contact.fields.Tags4__c.value;
        
    }
}
handleSelected(event){
    this.tagName = event.detail;

    console.log('tagname --->>' + this.tagName);
    
} 
handleNameChange(event) {
    this.contactId = undefined;
    console.log('label values --->>' + event.target.label);
    if (event.target.label === 'Enter Tag') {
        this.tagName = event.target.value;
    }

}
updateContact() {
    this.isLoaded = true;
    if(this.tags && this.tags1 && this.tags2 && this.tags3 && this.tags4){
        this.isLoaded = false;
    }else{
        if(this.tags == null){
            this.tags = this.tagName.toLowerCase();
            console.log('label values 0--->>' + this.tags);

        }else if(this.tags1 == null){
            this.tags1 = this.tagName.toLowerCase();
            console.log('label values 1--->>' + this.tags1);

        }else if(this.tags2 == null){
            this.tags2 = this.tagName.toLowerCase();
            console.log('label values 2--->>' + this.tags2);

        }else if(this.tags3 == null){
            this.tags3 = this.tagName.toLowerCase();
            console.log('label values 3--->>' + this.tags3);

        }else if(this.tags4 == null){
            this.tags4 = this.tagName.toLowerCase();
            console.log('label values 4--->>' + this.tags4);

        }
    const record = {
        fields: {
            Id: this.recordId,
            Tags__c: this.tags,
            Tags1__c: this.tags1, 
            Tags2__c: this.tags2,
            Tags3__c: this.tags3,
            Tags4__c: this.tags4,
           },
    };
    updateRecord(record)
        // eslint-disable-next-line no-unused-vars
        .then(() => {
            console.log('all' +' '+this.tags+' '+this.tags1+' '+this.tags2+' '+this.tags3+' '+this.tags4);
            this.isLoaded = false;
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Tag is Added',
                    variant: 'sucess',
                }),
            );
            
        })
        .catch(error => {
            this.isLoaded = false;
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error on data save',
                    message: error,
                    variant: 'error',
                }),
            );
        });

    }
  }
}

​​​​​​​