0

I have written some simple code which i will try to loop later but I am getting no success in trying to use SSJS to update SQL queries. I don't need to perform the actual query i just need to update the query text.

<script runat="server">
Platform.Load("core","1.1");


var qd = QueryDefinition.Init("abc-def-123-456");

var QT1 = "SELECT a.* FROM [data_extension] a";


qd.QueryText = QT1;


</script>

Please let me know where I am going wrong

1 Answer 1

0

What you are doing it's setting the variable/object in code. That will not update the Query, to do that you need to use this function
https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_queryDefinitionUpdate.htm

To use your exmample, code should look like this:

<script runat="server">
Platform.Load("core","1.1"); 

var qd = QueryDefinition.Init("abc-def-123-456");

qd.Update({
    QueryText: "SELECT a.* FROM [data_extension] a"
});


</script>
3
  • this hasn't worked for me i have also tried adding the Name bit to the code. Basically i first copied the code above changed the external key and the SQL. That ran successfully but didn't update the query text. I then tried again but with adding the Name part detailed in the documentation, again success on run but it did not update the query Commented Oct 11, 2019 at 13:46
  • @HariGovindan are you able to update same query in the same way in SFMC UI? Commented Oct 11, 2019 at 15:39
  • @MatueszBartkowiak actually you are right, i have tried your code again and retyped the SQL query and it works. There must be some hidden character from where i copy and pasted the original SQL. Thank you very much Commented Oct 16, 2019 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .