Regarding the execution order of ajax and gsftSubmit.

__ __163
Tera Contributor

 

function importmnakep() {
	var getanswer = "";
   if (!confirm("Run the import. Is it OK?")) {
    return false; //Abort submission
   }

    var sysparm_sysID = g_form.getUniqueValue();
    var sysparm_userID = g_user.userName;
    var sysparm_tableName_main = "base_table";
    var sysparm_tableName_insert = "import_table";
    var sysparm_fieldList = ['column1,column2,column3,column4,column5'];
    var sysparm_query = '';

    var gri = new GlideAjax('Import_Utils'); // Call Script Include
    gri.addParam('sysparm_name', 'Bulk_import'); // Call function
    gri.addParam('sysparm_sysID', sysparm_sysID);
    gri.addParam('sysparm_userID', sysparm_userID);
    gri.addParam('sysparm_tableName_main', sysparm_tableName_main);
    gri.addParam('sysparm_tableName_insert', sysparm_tableName_insert);
    gri.addParam('sysparm_fieldList', sysparm_fieldList);
    gri.addParam('sysparm_query', sysparm_query);
    gri.getXMLAnswer(function(answer) { //Ajax呼び出し
        if (answer.length > 0) { //戻り値チェック
			getanswer = answer;
			gsftSubmit(null, g_form.getFormElement(), 'import_mnakep');
			g_form.addInfoMessage(answer);//I don't want to delete this message
        }
    });
	
}
	if (typeof window == 'undefined') {
    deleteattachmentfile();
}

	function deleteattachmentfile() {
	
	var attachment = new GlideSysAttachment();
	var attachmentSysID = ""; //添付ファイルSysID
	var attachment_gr = new GlideRecord('sys_attachment');
	attachment_gr.addQuery('table_name', "base_table");
	attachment_gr.addQuery('table_sys_id', current.sys_id);
	attachment_gr.query();
	while(attachment_gr.next()){
		attachmentSysID = attachment_gr.sys_id;
		attachment.deleteAttachment(attachmentSysID);
	}
	action.setRedirectURL(current);
	}

 

I would like to implement the following behavior

1. Attach the file to the base record
2. Import the attachment information to the import destination record in the script include called with ajax
3.Delete the attachment file of the base record
4.Display the import result of "2" as a message at the beginning of the base record.
I ran the attached code to implement this.
However, the message that I want to display at the timing of "4", which is set in "g_form.addInfoMessage(answer);//I don't want to delete this message", disappears probably due to the action of deleting the file. .
I want to change the execution order so that the messages don't disappear, how can I do that?

0 REPLIES 0