- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2021 07:55 PM
HI Guys
Not sure If this group is the correct one to ask this question
I want to create an UI Action on knowledge table to be able to pass a value on a Select option from a GlideModal pop up into the Meta Field on the KB layout. I dont need execute any server script.. just the client one to add a new tag into the field Meta
I am using this article (Custom Glide Modal Dialog Boxes) as example but not sure why the function action is not working receiving this error
Uncaught TypeError: window.tagAction is not a function
at HTMLButtonElement.onclick
Here is the code
////////////////////////////////////////////////////////////////
//Client Side: Dialog box with choices
////////////////////////////////////////////////////////////////
function tagDialog(){
var gm = new GlideModal('tagKb');
//Sets the dialog title
gm.setTitle('Tag this KB');
//Set up valid custom HTML to be displayed
gm.renderWithContent('<div style="padding:15px"><p>What tag do you want to apply?</p><p><select name="tagging" id="tagPopUp" class="form-control"><option value="tag1" role="option">Tag 1</option><option value="tag2" role="option">Tag 2</option></select></p><div style="padding:5px;float:right"><button style="padding:5px;margin-right:10px" onclick="window.tagAction(this.innerHTML,jQuery(\'#tagPopUp\').val())" class="btn btn-default">Remove Tags</button><button style="padding:5px;margin-right:10px" class="btn btn-primary" onclick="window.tagAction(this.innerHTML,jQuery(\'#tagPopUp\').val())">Replace a Tag</button><button style="padding:5px" class="btn btn-primary" onclick="window.tagAction(this.innerHTML,jQuery(\'#tagPopUp\').val())">Add a Tag</button></div></div>');
//We'll use the windows object to ensure our code is accessible from the modal dialog
window.tagAction = function(thisButton, thisAction){
//Close the glide modal dialog window
gm.destroy();
//Submit to the back-end
if(thisButton=='Add a Tag'){
//if(thisAction=="cancelAll"){
g_form.setValue('meta',4);//writting down a tag value 4
jQuery("#sys_original.kb_knowledge.meta").val("https://"); // just a test to see how write
//Regular ServiceNow form submission
gsftSubmit(null, g_form.getFormElement(), 'tag_kb_article');
}
};
return false;//prevents the form from submitting when the dialog first loads
}
It looks like the error is related at the way the function tagAction is called from the Model popup. Like an scope problem
I was trying also by using windows.parent and window.opener.. but nothing is working
Any idea what Is the error?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2021 08:26 PM
Hi
due to security reasons you basically don't have access to the window object at client scripts. As a workaround you can try
top.window.tagAction
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2021 08:26 PM
Hi
due to security reasons you basically don't have access to the window object at client scripts. As a workaround you can try
top.window.tagAction
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 12:33 AM
Hi
Did my reply answer your question?
If so, please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
If not, please tell me what you are still missing.
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2021 07:35 AM
HI Mark!
I was off the past week and just see your solution
Thanks for your help!
Worked!