0 votes

How can I export the pictures stored in the Efficy Contacts table?

asked in WorkFlow / Serverscript by (7.4k points)

1 Answer

0 votes

Run the following script with Efficy 11.1+

The query selects all contacts where the picture field is not empty and exports the content to a folder.

/**
 * Export Contact pictures from Efficy table CONTACTS to disk
 * All are exported with ".png" extension
 * Kristof Pauwels, 22/02/2019
 * Run with Efficy SchedulerAdmin.exe
 */

/*
@import format from "format"
*/
function exportToDisk() {
    var exportFolder = "c:\\temp\\export\\",
        ext = ".png",
        consCont = Efficy.openConsultContext(ntCont),
        sql = "select K_CONTACT from <#TABLE NAME=CONTACTS> where PICTURE is not null order by K_CONTACT"
        ds = Efficy.sqlQueryDataset(sql, "")
        i = 1;

    Efficy.log(format("Selected $0 records for export to folder $1", ds.recordCount, exportFolder));
    while (!ds.eof) {
        var k_Contact = ds.fieldByName("K_CONTACT").asFloat,
            fileName = String(k_Contact) + ext,
            fullName = exportFolder + fileName,
            dsCont = Efficy.consult(consCont, k_Contact, false);

        smartDecompressToFile(dsCont.fieldByName("PICTURE").asString, fullName);

        Efficy.log(format("$0/$1 - exported $2", ds.recordCount, i, fileName));
        i++;
        ds.next;
    }

    Efficy.closeContext(consCont);
}
answered by (7.4k points)
1,249 questions
1,521 answers
1,859 comments
328 users