Can you use Cloud Code to validate data using queries?

4 posts, 1 answers
  1. Brad
    Brad avatar
    8 posts
    Member since:
    Dec 2008

    Posted 24 Sep 2013 Link to this post

    The built in cloud code seems to validate some format and range type scenarios but is there a way to query the database to see if a value already exists or if you need to retrieve a value from another content type?  Can you check for something like an existing username or email address?  If you need to check a value from another Content type to you have to use External HTTP requests?

    Something like the following uses the built in validation but  I would like to add the ability to query the database to check for existing values.

    Everlive.Events.beforeCreate(function(request, context, done) {
        var email = request.data.Email;
        var isValid = email && Everlive.Validation.validateEmail(email);
         
        if (!isValid) {
            Everlive.Response.setErrorResult('The "Email" field must be a valid email address.', 131, 500);
        }
         
        done();
    });

    Thanks,
    Brad
  2. Lyubomir Dokov
    Admin
    Lyubomir Dokov avatar
    43 posts

    Posted 25 Sep 2013 Link to this post

    Hello Brad,

    For now you have to use external HTTP calls to get data from another content type. In the future we plan to introduce the JavaScript SDK in the cloud code, so it will be much easier to work with data.

    Here is an example of how to construct the URL for the external HTTP request, so that it is not hard-coded:
    var parameters = Everlive.Parameters;
    var apiKey = parameters.apiKey;
    var masterKey = parameters.masterKey;
    var baseUrl = parameters.apiBaseUrl;
    var apiVersion = parameters.apiVersion;
    var url = baseUrl + "/v" + apiVersion + "/" + apiKey + "/" + "MyContentType";



    Regards,
    Lyubomir Dokov
    Telerik

    Big news for mobile app and .NET developers! Hear about it at our Release Keynote. Thursday, September 26th, 11AM EDT
    Do you enjoy Icenium? Vote for it in Windows IT Pro Community Choice Awards as Best Cloud Computing Product or Service (Category 5).
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  3. Brad
    Brad avatar
    8 posts
    Member since:
    Dec 2008

    Posted 25 Sep 2013 Link to this post

    Thanks for the cross content type example!

    If you are working within the same content type like Users, is there a more integrated way of querying data like checking for an existing username without having to resort to External HTTP requests?

    Thanks,
    Brad
  4. Answer
    Lyubomir Dokov
    Admin
    Lyubomir Dokov avatar
    43 posts

    Posted 27 Sep 2013 Link to this post

    Hi Brad,

    No, currently there is no way to do that without external calls.


    Regards,
    Lyubomir Dokov
    Telerik

    Do you enjoy Icenium? Vote for it in Windows IT Pro Community Choice Awards as Best Cloud Computing Product or Service (Category 5).
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
Back to Top