Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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.
 
 

 

9 REPLIES 9

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
Mega 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

This catalog client script is not VA supported due to the presence of the following variables in the script: g_form.hasAttachments.