Mandatory fields missing alert is showing even after filling values

anjanas
Kilo Contributor
document.body.addEventListener('click', function(event) {
            if (event.target.classList.contains("searchEMCIs")) {
		alert("clicked");
                if (document.contains(document.getElementById("emSearchPopup")))
                    document.getElementById("emSearchPopup").remove();
               var popupHtml = "";
popupHtml += '<div id="emSearchPopup" style="width: 100%;height: 50%;border: 1px solid #dfdfdf;bottom: 0;left: 0;right: 0;background: #fff;z-index: 2;">';
popupHtml += '</div>';
                document.querySelector("div.section-content").innerHTML += popupHtml;
            }
});

I have a client script in onLoad incident forms which adds a popup on click of a particular button (which I am adding through script).

When I am trying to add an incident record by filling all mandatory fields , click on the button which add popup html and then click on submit it says mandatory fields are missing.

This is happening in any scenario where I render extra html through client script. 

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

You can ignore the mandatory field check by using the following one line

 

g_form.checkMandatory=false;

-Anurag

I don't want to ignore mandatory check. Even if the values are entered it is not allowing user to submit the record, also this happens only when I add some html dynamically using client script

Yes i understand. but probably the dynamic way that you are using to populate the value is not going in sync with SN way and that is why even after you have populated the mandatory field its still giving you an error.

 

So what i would do is to manually check all the fields to ensure they are not blank(all the ones that are supposed to be blank) and then use the checkmandartory false and proceed.

-Anurag

I am not filling the mandatory fields through script. My script adds some extra html on click of some button (say its just adding an <h1> tag). Values for the mandatory fields I am entering manually only. And my script doesn't alter the html for these mandatory fields

I understand your point. Since Servicenow allows the user to configure the mandatory properties (like when they add some new properties they can decide whether it needs to be mandatory or not) if I make mandatory check false and start checking each field manually through my script it will be a double work I feel. 

Is it expected that if we add some extra html through script it behaves like this?