Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

VA conversational catalog items

preethigovi
Tera Contributor

Hi Team,

 

I need to make one of record producer to conversational item and i have made it.

There is one error that we must not use DOM objects in client script to make conversational.

This is the client script we use.

 

function onSubmit() {
   //Type appropriate comment here, and begin script below
    if((g_form.getValue('does_the_proposed_delegate_report_to_the_manager') == 'No') && this.document.getElementsByClassName('get-attachment').length == 0) {
        g_form.addErrorMessage(getMessage('You must attach a confirmation message from your proposed delegates manager with this ticket before proceeding.'));
        return false;
    }  
}
 
 
How we can modify so it supports VA.
 
 

 

5 REPLIES 5

Vishal_Jaiswal
Mega Guru

Hi @preethigovi ,

 

Please use script below and try.

function onSubmit() {

    var reportsToManager = g_form.getValue('does_the_proposed_delegate_report_to_the_manager');
    if (reportsToManager == 'No') {
        if (!g_form.hasAttachments()) {
    
            g_form.addErrorMessage(getMessage('You must attach a confirmation message from your proposed delegates manager with this ticket before proceeding.'));
            return false;
        }
    }

    // If the answer is 'Yes', or if it's 'No' and attachments DO exist, allow submission.
    return true;
}

 

 

Regards,

Vishal

Ankur Bawiskar
Tera Patron
Tera Patron

@preethigovi 

where are you doing this validation? native or portal view?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sarthak Kashyap
Kilo Sage

Hi @preethigovi ,

 

Can you please try with below script

 

function onSubmit() {
    var delegateReportsToManager = g_form.getValue('does_the_proposed_delegate_report_to_the_manager');
    var hasAttachment = g_form.hasAttachments(); 

    if (delegateReportsToManager == 'No' && !hasAttachment) {
        g_form.addErrorMessage(getMessage('You must attach a confirmation message from your proposed delegates manager before proceeding.'));
        return false;
    }

    return true;
}

 

g_form.hasAttachment() will check for attachments.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

preethigovi
Tera Contributor

Even, g_form.hasAttachments() is not supported in VA.

 

@Ankur Bawiskar , Validation done on portal.