RETSConnectorScript

From RETS Community Wiki

Jump to: navigation, search

RETS Connector is scriptable. The user interface can generate scripts like the one below for tasks created within the tool. Create a script with the Tools->Generate Script drop-down menu action.

//var username="";
//var password="";
WScript.Echo("Running script "+"Test Script");
WScript.Echo("Server Url: "+"http://retsServer/rets/login");
WScript.Echo("User Name: "+username);
WScript.Echo("Client Start Time: "+new Date());
var posInScript = "starting script";
var fso = null;
try {
    posInScript = "creating FileSystemObject";
    fso = new ActiveXObject("Scripting.FileSystemObject");
    posInScript = "creating FamlsRetsClient";
    var client = new ActiveXObject("FAMLS.RETS.Client.ComClient.FamlsRetsClient")
    posInScript = "logging into the server";
    if(client.Login("http://retsServer/rets/login",username,password)) {
        WScript.Echo("Server login time: "+client.HttpHeaderValue("Date"));
        WScript.Echo("Running step "+"1. All property");
        posInScript = "preparing step "+"1. All property";
        client.SelectTransaction("SEARCH");
        client.SetParameter("SearchType","Property");
        client.SetParameter("Class","ALL");
        client.SetParameter("Select","");
        client.SetParameter("Format","COMPACT");
        client.SetParameter("QueryType","DMQL2");
        client.SetParameter("Query","(MLSNumber=400000+)");
        posInScript = "requesting data in step "+"1. All property";
        if(client.Run()) {
            posInScript = "creating output file in step "+"1. All property";
            currentFileName = client.CreateTextFile("C:\\temp\\rets.txt",1)
            if(currentFileName.length=="") {
                WScript.Echo("ERROR: Unable to create data file "+"C:\\temp\\rets.txt");
            } else {
                var f = fso.OpenTextFile("C:\\temp\\rets.txt",8,true,-1);
                var line;
                posInScript = "reading server data in step "+"1. All property";
                while((line = client.ReadLine()) != null) {
                    posInScript = "processing data in step "+"1. All property";
                    switch(client.CompactLineType(line,"\t")) {
                        case "COLUMNS":
                            f.WriteLine(client.TranslateCompactLine(line,0));
                            break;
                        case "DATA":
                            f.WriteLine(client.TranslateCompactLine(line,0));
                            break;
                        default:
                            break;
                    }
                    posInScript = "reading server data in step "+"1. All property";
                }
                posInScript = "closing output file in step "+"1. All property";
                f.Close();
                WScript.Echo("Data file: "+"C:\\temp\\rets.txt");
                posInScript = "checking status code in step "+"1. All property";
                switch(client.RetsStatusCode) {
                    case 0:
                    case 20201: 
                    case 20208:
                        WScript.Echo("Data downloaded. RETS Status code = "+client.RetsStatusCode);
                        break;
                    default: 
                        WScript.Echo("ERROR downloading data: RETS Status code = "+client.RetsStatusCode);
                        break;
                }
                WScript.Echo("RETS Status text: "+client.RetsStatusText);
            }
        } else {
            posInScript = "reporting failure in step "+"1. All property";
            WScript.Echo("ERROR in step "+"1. All property"+". Client failed: "+client.ResponseError);
        }
        posInScript = "closing step "+"1. All property";
    } else {
        WScript.Echo("ERROR: Unable to log into server. "+client.LoginText);
    }
} catch(ex) {
    WScript.Echo("ERROR while "+posInScript+": "+(ex.toString()=="[object Error]" ? ex.message : ex));
} finally {
    client = null;
    fso = null;
}
Personal tools
wiki.rets.org