2

I've built a CloudPage which runs SQL queries quickly without having to use automation studio.

The SSJS that runs the query works perfectly, but I'm also trying to use this function to also update a data extension to use as an audit log of it being used. It's supposed to simply update a data extension called Query Log. It just has four columns, Target, Type, Definition, andRunDate. The data extension is set up and all fields are nullable, but I can't get it to run. It doesn't give me an error that I can see and the page loads fine, but it doesn't add a record to the data extension. This is the code:

<script>
    Platform.Load("Core","1");
var api = new Script.Util.WSProxy();
var target = Variable.GetValue("@target");
var type = Variable.GetValue("@type");
var qdef = Variable.GetValue("@definition");
/*Build DE Object*/
var updateObject = {
    CustomerKey: 'QueryLog',
    Properties: [
        {
            Name: 'Target'
            Value: target
        },
        {
            Name: 'Type'
            Value: type
        },
        {
            Name: 'QueryDef'
            Value: definition
        },
        {
            Name: 'RunDate'
            Value: Platform.Function.Now()
        }
    ]
};

var options = {SaveOptions:[{'PropertyName':'*',SaveAction:'UpdateAdd'}]};
var res = api.updateItem('DataExtensionObject',updateObject,options);
</script>
2

I'd put a try/catch around the whole thing and see what you get. You're also missing the runat attribute on your script tag.

<script runat="server">
Platform.Load("Core","1");

try {

    var api = new Script.Util.WSProxy();
    var target = Variable.GetValue("@target");
    var type = Variable.GetValue("@type");
    var qdef = Variable.GetValue("@definition");

    /*Build DE Object*/
    var updateObject = {
    CustomerKey: 'QueryLog',
    Properties: [
        {
            Name: 'Target'
            Value: target
        },
        {
            Name: 'Type'
            Value: type
        },
        {
            Name: 'QueryDef'
            Value: definition
        },
        {
            Name: 'RunDate'
            Value: Platform.Function.Now()
        }
    ]
    };

    var options = {SaveOptions:[{'PropertyName':'*',SaveAction:'UpdateAdd'}]};
    var res = api.updateItem('DataExtensionObject',updateObject,options);

} catch (e) {
    Write("<br>e: " + Stringify(e));
}
</script>
  • Thanks. First I forgot the commas in the name-value pairs, so I put those back in, and the script runat. Ran it with the try/catch but it didn't give me an explanation - the Stringify types nothing. – TCassa Nov 29 '18 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.