JavaScript error in your browser console in portal

Niyeeti Dey
Tera Contributor

Hi Everyone,

 

I am getting error in portal  JavaScript error in your browser console while its working fine in native view

 

Client Script:onSubmit

 

function onSubmit() {

if (g_form.getValue('u_report_obtained') == 0 && g_form.getValue('u_q1') == 'yes') //report obtained= false and and q1 is yes {

var attachments = document.getElementById('header_attachment_list_label'); if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {

g_form.addErrorMessage("Please attach the latest third-party audit report and respond to the attestation questions below.");

} else { return false; } } }

6 REPLIES 6

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Niyeeti Dey ,

Please try below code :-

 

function onSubmit() {
    var alertWord = "Please attach the latest third-party audit report and respond to the attestation questions below.";

    try {
        var attachments = g_form.getControl('header_attachment_list_label');
        if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
            alert(alertWord);
            return false;
        }

    } catch (e) { //For Service Portal

        var count = getSCAttachmentCount();

        if (count <= 0) {
            alert(alertWord);
            return false;
        }
    }
}

 

You will have to create UI script as well for this as below :-

UI Script: GlobalCatalogItemFunctions

function getSCAttachmentCount() {

  var length;

  try {

  length = angular.element("#sc_cat_item").scope().attachments.length;

  } catch(e) {

  length = -1;

  }

  return length;

}

 

Ref:Require attachment for catalog item in Service Portal 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Thank you @Gunjan Kiratkar  its working fine in portal now but getting error in native view, as per my requirement its should work in both view.

 

onSubmit script error: ReferenceError: getSCAttachmentCount is not defined:

Hi @Niyeeti Dey ,

Use the script from @Ankur Bawiskar's article.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Ankur Bawiskar
Tera Patron
Tera Patron

@Niyeeti Dey 

it seems you are trying to make attachment mandatory for your catalog item

I have created blog for this couple of years ago; check that and enhance

Verify Mandatory Attachments Count on Catalog Item 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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