Highlighted
Respected Contributor.
Respected Contributor.
1069 views

Launch unload from JS or other way

Hello experts,

I have a following task: we have a table where we store filenames and queries for objects that are being modified by us. What I need to do is: when a record to our modified_objects_table is being added i need to create a unl-file of the record. For example, our modified_objects_table has two fields: "filename" and "query". And my script should create an unl-file that would contain the record(s) selected by "query" from "fielname" table.

I tried to use us.unload.process RAD for this, but got the following error:

"The unload could NOT be created in the path/filename specified.  Either the correct config record is missing, the path (or folder) does not exist, or there is an access problem.
Application: file.unload, has completed with errors, check other messages.  26/09/17 18:10:12"

Any ideads how to bypass this error? Or maybe there are other ways to accomplish this?

0 Likes
16 Replies
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

	var $ = lib.c.$;
	var path = './unloads/unloadex_' + new XMLDate(new Date()).getISODate() + '.unl';
	var unloadName = 'UnloadEx';
	var fUnload = $("unload", SCFILE_READONLY).select("name=\"" + unloadName + "\"").uniqueResult();
	var rc = callrad("us.unload.process", ["name","prompt"], [fUnload, path]);
0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

I believe the last line of the script should look like this:

var rc = $.callrad("us.unload.process", ["name","prompt"], [fUnload, path]);

 But I still get error, but now it's different:

Cannot evaluate expression  (us.unload.process,check.action)
Bad arg(1) oper = (us.unload.process,check.action)
Cannot evaluate expression "The record load option must be \"update\" or \"add only\"." in 1815 (us.unload.process,check.action)

0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

I believe the last line of the script should look like this:

My code is working too on 9.52 🙂

Where do you run the script? From win client? Try to uncheck "Client Side Load/Unload" checkbox, restart client and try again.

0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

And set field "unload" to True in unload file.

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

I'm working on 9.50.0025. And without the small correction in yours script - it didn't work at all.

Tried to uncheck the "Client Side Load/Unload" checkbox - still same error. Tried from Web - same error again.

Here's how my code looked like before your advice:

	var now = new Date();
	var day = now.getDate()<10?"0"+now.getDate():now.getDate();
	var month = now.getMonth()+1<10?"0"+(now.getMonth()+1):(now.getMonth()+1);
	var year = now.getFullYear();
	var hour = now.getHours()<10?"0"+now.getHours():now.getHours();
	var minute = now.getMinutes()<10?"0"+now.getMinutes():now.getMinutes();
	var second = now.getSeconds()<10?"0"+now.getSeconds():now.getSeconds();
	var strDate = day+month+year+"_"+hour+minute+second;
	var filename = "TMP"+"_"+sf.operator()+"_"+tablename+"_"+strDate;

	var unl = new SCFile("unload");
	unl["name"] = filename;
	unl["unload"] = true;
	unl["record"][0]["filename"] 	= tablename;
	unl["record"][0]["query"] 		= qry;
	unl["record"][0]["datamap"]		= false;
	var rc = unl.doAction("add");
	if (rc != RC_SUCCESS){
		print("Failed to create backup!");
		return false;
	}
filename = "C:/TMP/"+filename+".unl"; var rteReturnValue = new SCDatum(); var argNames = new SCDatum(); var argVals = new SCDatum(); argNames.setType(8); argVals.setType(8); argNames.push("name", "prompt"); argVals.push(unl, filename); vars["$G.bg"] = true; system.functions.rtecall("callrad", rteReturnValue, "us.unload.process", argNames, argVals, false); vars["$G.bg"] = false;

 

Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

This code on my environmen is working fine.

var sf = system.functions;
test('msglog', 'true');

function test(tablename, query) {
	var now = new Date();
	var day = now.getDate()<10?"0"+now.getDate():now.getDate();
	var month = now.getMonth()+1<10?"0"+(now.getMonth()+1):(now.getMonth()+1);
	var year = now.getFullYear();
	var hour = now.getHours()<10?"0"+now.getHours():now.getHours();
	var minute = now.getMinutes()<10?"0"+now.getMinutes():now.getMinutes();
	var second = now.getSeconds()<10?"0"+now.getSeconds():now.getSeconds();
	var strDate = day+month+year+"_"+hour+minute+second;
	var filename = "TMP"+"_"+sf.operator()+"_"+tablename+"_"+strDate;

	var unl = new SCFile("unload");
	unl["name"] = filename;
	unl["unload"] = true;
	unl["record"][0]["filename"] 	= tablename;
	unl["record"][0]["query"] 		= query;
	unl["record"][0]["datamap"]		= false;
	var rc = unl.doAction("add");
	if (rc != RC_SUCCESS){
		print("Failed to create backup!");
		return false;
	}
	var rteReturnValue = new SCDatum();
	var argNames = new SCDatum();
	var argVals = new SCDatum();
	argNames.setType(8);
	argVals.setType(8);
	argNames.push("name", "prompt");
	argVals.push(unl, filename);
	vars["$G.bg"] = true;
	system.functions.rtecall("callrad", rteReturnValue, "us.unload.process", argNames, argVals, false);
	vars["$G.bg"] = false;
}

 

Console output. Sorry for russian lang.

Запись "выгрузка" добавлена.
Вывод в TMP_mgrekov_msglog_27092017_104142 завершен. Обработано 2833 записей, 0 приложений RAD.

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Where did you launch it from? Are your server and client are local? Where is the file saved, locally or on the server?

PS Russian is ok, Я тоже из России 😃

0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

I run it from ScriptLibrary in Windows Client. Client and server are located on different machnies. The file is saved on the server to the Run directory.

 

Highlighted
Respected Contributor.
Respected Contributor.

I have client and server both on my local machine. Tried to execute the script on remoted server - it works, but only in the "server-side load/unload" mode.

Now the task is to make system create unload on server with "Client side load/unload" checkbox checked. Is that possible?

0 Likes
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

H @Nick_Karpushkini,

not sure if it's possible to save it via "client unload". But if the user triggers the action to create the unload,
then it's maybe easier to create the unload file via JS and then "redirect" the user to the "process/choose file" form.

Then the user can decide, where the file should be saved.
Or... just use the server side unload and share the target directory in your network 😉

I use the following script to export unloads via a scheduler:

/**
 * Creates a scheduler record to export records
 * via the unload utilities.
 *
 * @author     Marcus Reinhardt, webstone@gmail.com
 *
 * @example
 * 
 * var $                = system.library.c.$;
 * var fRevisionRecord  = $('myrevisiontable').select('revision.id=123456').uniqueResult();
 * var bBackupCreated   = createUnloadViaScheduler( fRevisionRecord );
 *
 *
 * @param      {SCFile}   fTable  The file
 *
 * @return     {boolean}
 */
function createUnloadViaScheduler(fTable){
     
    var cTargetFile = "C:/unloads/backup/" + fTable['tablename'] + ".unl";

    var fSchedule           = new SCFile("schedule");
    fSchedule._class        = "linker";
    fSchedule.expiration    = new Date();
    fSchedule.application   = "unload.background";
    fSchedule.strings[0]    = 'append';
    fSchedule.strings[10]   = 'winnt';
    fSchedule.strings[11]   = 'binary';
    fSchedule.strings[12]   = 'create';
    fSchedule.strings[13]   = 'update';
    fSchedule.strings[15]   = 'false';
    fSchedule.strings[16]   = 'false'
    fSchedule.strings[2]    = cTargetFile;
    fSchedule.strings[3]    = fTable['query'];
    fSchedule.strings[4]    = fTable['tablename'];
    fSchedule.name          = "unload file for "+fTable['tablename']+" with query "+fTable['query'];      
    
    var rcInsert = fSchedule.doInsert();

    return ( rcInsert == RC_SUCCESS ) ? true : false;
}

 

 

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Hello Marcus,

Thanks for the answer, but that's not what I need. The full description of task is:

We have a record, which has, among others, two fields, "table.name" and "unique.query". What I need to do is: when a user presses the "Add" button I should create an unl-file of the record(s) from table "table.name" selected by "unique.query" and attach the created unl-file to the record that user is currently adding. This should happen exactly at the moment when user creates a record, so the scheduler is not an option.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.