document.getElementById not working

wakespirit
Kilo Guru

Dear all,

I have a record producer that I am displaying in a GlideModal using below script :

var gform=new GlideModal('test_producer',false,'modal-lg');

Then I have a UI page named "test producer" define as below :

HTML script :

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
		<button id="close" onclick="closeAck()" type="button">$[gs.getMessage("Close")]</button>
	<div>
	
	<iframe id="rp_frame" src="/com.glideapp.servicecatalog_cat_item_view.do?v=1${AMP}sysparm_id=a57bed012f8ba30061999bacf699b64e" width="800" height="600">
		</iframe>
		
	</div>
<script>

addLoadEvent( function() {
onLoadFunction();

});


</script>	
</j:jelly>

Client Script :

function closeAck() {
	alert("CLOSE ACK REACH");
	GlideDialogWindow.get().destroy();
	//saveProducer();
}

function onLoadFunction()
{
   alert("FRAME LOADED");
	var iframe = document.getElementById('rp_frame');
	 if(iframe){
       
	 var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
	  var button = innerDoc.getElementById("submit_button");
		 if(button){
		   var mybuttonValue= button.value;
			 	alert("SUBMIT BUtton : " + mybuttonValue)  ;
		 }
		 else{
			 alert("SUBMIT BUTTON NOT FOUND")  ;
		}
    }
	else{
			 alert("IFRAME NOT FOUND")  ;
	}
	
}

What I am trying to do is to get the Submit_button of the record procuder which is embeded in the Iframe.

For some reason I cannot reach the buttton id using getElement, the alert message "SUBMIT BUTTON" is displayed

What i am doing wrong ? does it means the button is not yet ready when onload method is called ? how should I change my script to be able to reach the submit button 
?

Below is the debug view element of my button I need to catch :

<button type="button" id="submit_button" name="submit_button" class="request_catalog_button header_button btn cat-btn btn-primary" href="#" onclick="saveProducer('');" title="" aria-label="Submit" data-html="true" role="button" data-original-title="Submit">
			Submit
			<span class="sr-only">Submit</span></button>

 

once I am able to access this button, I need to register to the onclick event in order to run a script, but as you can see from below the click event of the button is already calling saveProcuder(''), can I register to this event and run an other script in parallel ?

Thnaks to help me to know why i cannot fetch my button and register to its click event

regarsd

13 REPLIES 13

Alikutty A
Tera Sage

Hello,

On your client script, you should set the Isolate script flag to false. You can do it from a list view or after adding this field on your client script form.

Please refer to the following link for details: https://community.servicenow.com/community?id=community_blog&sys_id=c5c46364dbba6b007d3e02d5ca9619cb

Thanks!

sorry did not understand, what does that mean ?

 

My client script is the client section of my UI page and I do not have this Isolate Script flag your mentionned in your link ?

Oh, I misunderstood that UI page was called from a client script

No the UI page is called from a UI action using following :

var gform=new GlideModal('test_producer',false,'modal-lg');

And in my UI page script configuration the flag you mentionned is set to false :

find_real_file.png 

 

 

test_producer is the name of the UI page where I post at begining the HTML part and the Client Script part.

So what should I do in order my script to get the submit_button works ?

Any idea?