Alternative method for document.getElementById()

Anusha Dande
Tera Contributor

Hi

 

Can anyone please help with an alternative method for document.getElementById() as DOM manipulation should be avoided in client scripts

Below is the example code

try

{

var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
if ((g_form.getValue('u_transition_personal_sim_card_to_corporate_mobile_plan_is_required') == 'yes')) {
alert('Document attachment is mandatory for request submission.');
return false;
}
}

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please use the solution mentioned in the below article:-

 

https://www.basicoservicenowlearning.in/2020/10/attachment-mandatory.html

 

Please mark my answer as correct based on Impact.

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this is for catalog item or native form?

As per my understanding no other way to replace DOM

What's your requirement?

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

Hi Ankur,

 

This is for catalog item and requirement to avoid DOM manipulations like document,$,gel

Can you please suggest an alternative method or alternative approach

 

Thanks,

Anusha

Hi,

For native?

I don't think. You can try to use onSubmit with Synchronous Ajax

Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit

How To: Async GlideAjax in an onSubmit script

Asynchronous onSubmit Catalog/Client Scripts in ServiceNow

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

@Anusha Dande 

try this script

try{
	var	attachmentCount = getCurrentAttachmentNumber();
	if ((g_form.getValue('u_transition_personal_sim_card_to_corporate_mobile_plan_is_required') == 'yes') && attachmentCount == 0) {
		alert('Document attachment is mandatory for request submission.');
		return false;
	}
}

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