Modal, submit botton (flow error)

tomaslindev
Mega Guru

Good to all,
I have created a "Ad External Comment" button, that a modal to introduce text is opened at the click; When it relates, a flow must be launched that introduces the comment as a public comment at the Primary_Ticket. This flow will be launched as a system user, and in the public comment the person who has written will be indicated.

I have already created the button, the modal and the flow (when I execute it in a background script it works correctly), but in the modal, the submit does not run the flow and I do not find the error. Any ideas ?

 

Server Script:

// ========================
// External Comment via Flow
// ========================
if (input && input.action === 'add_external_comment') {
	try {
		gs.info(" [EXTERNAL COMMENT] Lanzando subflow con: comment_text=" + input.comment_text +
		        ", author_name=" + input.author_name +
		        ", ur_sys_id=" + input.ur_sys_id);

		var flowAPI = new sn_fd.FlowAPI();
		var flowInputs = {
			comment_text: input.comment_text,
			author_name: input.author_name,
			ur_sys_id: input.ur_sys_id
		};
		flowAPI.startSubflow('[ATC]Add External Comment to UR', flowInputs);

		gs.info("[EXTERNAL COMMENT] Subflow lanzado correctamente");
		data.result = 'comment_launched';

	} catch (ex) {
		gs.error(" [EXTERNAL COMMENT] Error al lanzar subflow: " + ex.message);
		data.result = 'error_starting_subflow';
	}
}

 

Client Script (controller):

 

c.submitComment = function() {
	if (!c.externalCommentText || c.externalCommentText.trim() === '') {
		spUtil.addErrorMessage("El comentario no puede estar vacío.");
		return;
	}

	c.server.update({
		action: 'add_external_comment',
		comment_text: c.externalCommentText.trim(),
		author_name: c.data.currentUserName,
		ur_sys_id: c.data.sys_id
	}).then(function(response) {
		if (response.data.result === 'comment_launched') {
			spUtil.addInfoMessage("Comentario enviado correctamente.");
			c.cancel();
		} else {
			spUtil.addErrorMessage("Error al lanzar el subflow. Código: " + response.data.result);
		}
	});
};

  

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@tomaslindev 

logs are coming in the widget server side?

you can always use Create code snippet to get the script to trigger subflow from script

AnkurBawiskar_0-1754485119036.png

 

try {
		var inputs = {};
		inputs['mydate'] = ; // Date 
		inputs['mrvsdata'] = ; // Array.Object 

		// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
		// sn_fd.FlowAPI.getRunner().subflow('global.testing_mrvs_subflow').inBackground().withInputs(inputs).run();
				
		// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
		var result = sn_fd.FlowAPI.getRunner().subflow('global.testing_mrvs_subflow').inForeground().withInputs(inputs).run();
		var outputs = result.getOutputs();

		// Get Outputs:
		// Note: outputs can only be retrieved when executing synchronously.
		var myjsonstring = outputs['myjsonstring']; // String
		
	} catch (ex) {
		var message = ex.getMessage();
		gs.error(message);
	}

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

Hello @Ankur Bawiskar , first of all, thank you for your response.
Following your comment, I noticed that the flow is not configured as "Callable by Client API." Considering that it has to be executed through a modal in the portal, clicking the submit button could have an impact. Could that be the error?

@tomaslindev 

if your control is being passed to server side and you are using proper syntax to invoke the flow then it should work

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