HTTP request from alfresco javascrit file

cancel
Showing results for 
Search instead for 
Did you mean: 
abakachiali
Member II

HTTP request from alfresco javascrit file

I am new in alfresco and I create a rule that execute a javascript file when a file arrives in a directory (My javascript it inside data dictionnary script file). However, this javascript script must send a http get request to a remote server but I can not use the alfresco remote. Can you suggest a solution? Thank you

My javascript code:

function main() {
    var name = document.name;
    var username = "";
    var msgContent = "";
    var siteName = document.siteShortName;
    var firstName = person.properties.firstName;
    var lastName = person.properties.lastName;

    if (siteName == null) {
        if (logger.isLoggingEnabled())
            logger.log("Erreur");

        return;
    }
    if (firstName != null) {
        username = username + firstName + " ";
    }
    if (lastName != null) {
        username = username + lastName;
    }
    msgContent = username + " a ajouté un nouvel élément de contenu " + name + " au site " + siteName;

    if (logger.isLoggingEnabled()) {
        logger.log(encodeURIComponent(msgContent));
    }
    var connector = remote.connect("gedrepportremote");
    var result = connector.get("/api/sendSMS?siteName=" + encodeURIComponent(siteName) + "&msgContent="+encodeURIComponent(msgContent));
    if (result.status == 200) {
        return JSON.parse(result);
    } else if (result.status == 403) {
        
    } else {
        return null;
    }
}

main();

I have this error : "remote is not defined". I tried this HTTP Request from WebScript in Alfresco but it doesn't work for me.

1 Reply
mehe
Senior Member II

Re: HTTP request from alfresco javascrit file

The "remote" object is not availabe by default when using rule scripts. See Axel Faust‌ answer in Call a repository webscript from a rule script 
He also describes how to enable the "remote" root object...