How to popup message or alert on Servicenow portal for Quantity drop-down field ?

Virendra K
Kilo Sage

Hi All,

I want to popup a message /alert if user is selecting more than 8 quantity in the below drop down field(snap 1). 

Do I need to do the coding in HTML template or Client script or Server script ?  I have find coding part for this field in HTML template (snap2)

Please let me know how I can popup message and stop user to select more than 8 number /qty ? 

Snap1:

find_real_file.png

 

Snap2:

find_real_file.png

 

Thank you.

Regards,

Virendra

 

 

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra Kharkar 

If you try that approach it would be global change I believe since it will for all catalog items.

1)  If you want this for all catalog items then you can disable those 2 drop down choices of 9 and 10 for sc_cart_item table

find_real_file.png

2) if you want for specific catalog item then you can have onSubmit catalog client script to check for quantity

Ensure: Isolate script is set to false; this field is not on form but from list you can set it to false; by default it is true

Sample Script below; it worked for me in native and portal both

Note: this includes using DOM manipulation

function onSubmit() {
	//Type appropriate comment here, and begin script below

	if(window == null){
		var z = this.document.getElementsByClassName("select2-chosen");
		if(z[1].innerHTML > 8 ){
			alert('Please select value less than 8');
			return false;
		}
	}
	else{
		var quantity = $j('#quantity').val();
		if(quantity > 8){
			alert('Please select value less than 8');
			return false;
		}
	}
}

find_real_file.png

Regards
Ankur

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

Hi Ankur,

It helped me lot, but when I applied above code, I am getting error on portal.When I saw it in console. its is related to "innerHTML"

error msg is , "Cannot read property 'innerHTML' of undefined". Also I am new to the portal but I would like to know, how and where we can fins the control name on portal like you mentioned for dropdown "select2-chosen" ?

snap:

find_real_file.png

Thanks,

Virendra

@Virendra Kharkar 

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so others with similar questions/issues can find your posting quickly.

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra Kharkar 

Let me know if that answered your question.

If so, please mark appropriate response as correct & helpful so others with similar questions/issues can find your posting quickly.

Regards
Ankur

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