How to call a UI Action through a URL

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2020 06:45 AM
Hi, friends!
I need your help.
I have to open a form with the tabs enabled.
This has to be done when the user clicks the New button from another form:
(FORM 1)
This is the code of the window above:
My code only works when the user clicks the New button on the original form:
FORM 2
Any suggestion ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2020 12:46 PM
There may be other ways to do this, but you could use a GlideAjax call from your UI Page to initialize the new record and respond with the sys_id, then instead of putting a sys_id of -1 in the URL you would use the sys_id of the newly created record.
Update your UI Page to replace the criarNovo() function with something like this:
function criarNovo(){
var ga = new GlideAjax('CadastroPreventivaAjax');
ga.addParam('sysparm_name','inicializarNovo');
ga.getXML(abrirNovo);
}
function abrirNovo(response){
var pend_ativ = g_form.getUniqueValue();
var resposta = response.responseXML.documentElement.getAttribute("answer");
resposta = trim(resposta);
if (resposta != "") {
var url = 'nav_to.do?uri=u_sgmp_cadastro_preventiva.do?sys_id='+resposta+'%26sysparm_pend='+pend_ativ+'';
window.open(url);
GlideDialogWindow.get().destroy();
}
else {
// Put your error handling here
}
}
Then you will need to create a Script Include to handle the GlideAjax call. You can name it whatever you would like, just remember to update the UI Page to call it correctly. I have used GlideRecord.canCreate() to verify that the user can insert records on that table.
Script Include
Name: CadastroPreventivaAjax
Client Callable: true
var CadastroPreventivaAjax = Class.create();
CadastroPreventivaAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
inicializarNovo: function () {
var gr = new GlideRecord('u_sgmp_cadastro_preventiva');
if (gr.canCreate()) {
gr.initialize();
gr.insert();
return gr.getValue("sys_id");
}
else {
return null;
}
}
});
Hopefully this works for you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2020 04:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2020 07:30 AM
I see one error I made when modifying your script. I forgot to include the variable definition for pend_ativ from your original code. It should go in the abrirNovo() function above the variable definition for resposta. I will edit my original post to add it.
function abrirNovo(response) {
var pend_ativ = g_form.getUniqueValue();
var resposta = ...
Other than that, it looks like you added the inicializarNovo() function to an existing script include. Make sure the script include you put the AJAX functions in is client callable, and that the object prototype the functions are declared in extends the AbstractAjaxProcessor object. If the prototype does not extend AbstractAjaxProcessor, then your GlideAjax calls will fail.
If all of that is set correctly and the button is still not working, you can check for errors on the client side by looking for errors in the browser console (in the browser developer tools).