1

I've created a server-side JavaScript activity to create an image and run in automation, which is throwing an error, but the script working well in landing page:

Value cannot be null. Parameter name: principal can not be nullSystem.ArgumentNullException: Value cannot be null. Parameter name: principal can not be null at ExactTarget.Core.StackSettingCollection..ctor(IAccountContext principal, String category, CacheType cacheType) at ExactTarget.ContentManagement.Instrumentation.Instruments.StatsDInstrument.<.ctor>b__1() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue()
at ExactTarget.ContentManagement.Instrumentation.Instruments.StatsDInstrument.<>c__DisplayClass9.b__8(Int64 elapsedMilliseconds) at ExactTarget.ContentManagement.Services.Assets.AssetService.Insert(IAssetV2 item) at PartnerAPIImplementation.ContentManagement.AssetImpl.CreateSingle(CreateOptions options, APIObject apiObject)

Here's the sample code

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

        var testingDE1 = DataExtension.Init("My Demo DE");
        testingDE1.Rows.Add({Field1:349,Field2:'job starting'});


        var asset = Platform.Function.CreateObject("Asset");
        var nameIdReference = Platform.Function.CreateObject("NameIdReference");
        Platform.Function.SetObjectProperty(nameIdReference, "Id", 199); //html block type
        Platform.Function.SetObjectProperty(asset, "AssetType", nameIdReference);
        testingDE1.Rows.Add({Field1:350,Field2:'job processing'});
        var txt = "<table width='100%' cellspacing='0' cellpadding='0'><tr><td align='center'><img src='https://www.cathaypacific.com/content/dam/focal-point/digital-library/destinations/dublin-dub/dublin-dub-offer.jpg/jcr:content/renditions/cq5dam.rendition.900.600.jpg' height='600' width='900' style='display: block; padding: 0px; text-align: center; height: auto; width: 100%; border: 0px;'></td></tr></table>";
        Platform.Function.SetObjectProperty(asset, "Name", "0033");
        Platform.Function.SetObjectProperty(asset, "Content", txt);
        Platform.Function.SetObjectProperty(asset, "ContentType", "imageblock");
        var statusAndRequest = [0,0];
        testingDE1.Rows.Add({Field1:234,Field2:'Hello World!!!!'});
        var response = Platform.Function.InvokeCreate(asset, statusAndRequest, null);
        testingDE1.Rows.Add({Field1:351,Field2:'job ending'});
        testingDE1.Rows.Add({Field1:352,Field2:response});
        var status = statusAndRequest[0];
        var requestID = statusAndRequest[1];
        testingDE1.Rows.Add({Field1:353,Field2:status});
        testingDE1.Rows.Add({Field1:354,Field2:requestID});

    } catch (err) {
        var testingDE = DataExtension.Init("My Demo DE");
        testingDE.Rows.Add({Field1:123,Field2:Stringify(err)});
        testingDE.Rows.Add({Field1:234,Field2:'Hello World!!!!'});
        //Write(Stringify(err) + "</br>");
    }
</script>
1
  • anybody have an idea for this issue? – Terry Nong May 21 '18 at 2:43
0

I had a similar issue with creating a code snippet. I solved my problem in using the REST API

var url = 'https://auth.exacttargetapis.com/v1/requestToken';
var contentType = 'application/json';
var payload = '{"clientId":"' + clientId + '",';
payload += '"clientSecret":"' + clientSecret + '"}';

var accessTokenResult = HTTP.Post(url, contentType, payload);
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).accessToken;

url = "https://www.exacttargetapis.com/asset/v1/content/assets";
var headerNames = ["Authorization"];
var headerValues = ["Bearer " + accessToken];

payload = "{";
payload += ' "category": {';
payload += '  "id": 1234,';
payload += '  "name": "code snippets"';
payload += " },";
payload += ' "assetType": {';
payload += '  "id": 220,';
payload += '  "name": "codesnippetblock"';
payload += " },";
payload += ' "content": "code-snippet code",';
payload += ' "description": "description for code-snippet",';
payload += ' "name": "name of code-snippet"';
payload += "}";

var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
var statusCode = result["StatusCode"];
var response = result["Response"][0];

Code snippet creation in Automation Studio script

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.