Modal Window in Client UI Action not working

jordimsant
Tera Guru

I have written this UI Action:

function onClick() {
    var gm = new GlideModal('glide_confirm_basic');
	var validation_message = "Aquesta acció farà que la factura deixi de ser vàlida i se substitueixi per una de nova que quedarà adjuntada en el camp 'Factura modificada'. Estàs segur que vols continuar?";
    gm.setTitle("Estàs a punt de modificar una factura!");
    gm.setPreference('title', validation_message);
    gm.setPreference('onPromptComplete', onComplete);
    gm.render();
}

function onComplete(answer) {
	if (answer == 'ok') {
		// Crida el codi del servidor de la mateixa UI Action
		g_form.addInfoMessage('missatge');
		gsftSubmit(null, g_form.getFormElement(), 'mod_factura_serv');
	}
}

It is obviously a Client UI Action. When I press the form button, the modal window displays, but when I press the "Ok" button nothing happens (the info message "Missatge" is not displaying). I have created another UI Action in server side called "mod_factura_serv" with the following code:

// Generem la copia de la nostra factura
var originalID = current.getUniqueValue();
var original = new GlideRecord('x_tntsl_tmn_factur_factures');
original.get(originalID);
original.insert();

var numManager = new global.NumberManager();
var nova = new GlideRecord('x_tntsl_tmn_factur_factures');
nova.addEncodedQuery();
nova.orderByDesc('sys_created_on');
nova.query();
if(nova.next()) {
	nova.number = numManager.getNextNumber('x_tntsl_tmn_factur_factures').toString();
	nova.estat = 'modificat';
	nova.data_de_factura = '';
	nova.update();
}

// Marquem la factura antiga com a invalidada
current.estat = 'invalidat';
current.factura_modificada = gr.getUniqueValue();
current.update();

// Afegim les tasques que hi havia a la antiga factura a la nova
var novaID = nova.getUniqueValue();
var gr = new GlideRecord('x_tntsl_tmn_factur_facturacio_m2m');
var query = 'x_tntsl_tmn_factur_factures=' + originalID;
gr.addEncodedQuery(query);
gr.query();
while(gr.next()) {
	gr.x_tntsl_tmn_factur_factures = novaID;
	gr.insert();
}

I am sure the Server side part is not wrong by itself, because I computed it in Background Scripts and it does what it has to do, it is not being called by the first one. Anybody notices what am I doing wrong?

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@jordimsant 

update as this

function onClick() {
    var gm = new GlideModal('glide_confirm_basic');
    var validation_message = "Aquesta acció farà que la factura deixi de ser vàlida i se substitueixi per una de nova que quedarà adjuntada en el camp 'Factura modificada'. Estàs segur que vols continuar?";
    gm.setTitle("Estàs a punt de modificar una factura!");
    gm.setPreference('title', validation_message);
    gm.setPreference('onPromptComplete', onComplete);
    gm.render();
}

function onComplete() {
    // Crida el codi del servidor de la mateixa UI Action
    g_form.addInfoMessage('missatge');
    g_form.submit('mod_factura_serv');
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@jordimsant 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

kaushal_snow
Mega Sage

It appears that the issue with your GlideModal in the Client UI Action is due to the incorrect usage of gsftSubmit() in the callback function.  Mostly this method is intended for server-side scripts and is not suitable for client-side operations within a GlideModal. Instead, you should use g_form.submit() to submit the form from the client-side.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/