0

I am using the below SSJS to clear out a data extension. It works well in the Parent BU but when I run it in a Child Business Unit it fails

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


var payload = '';
var username = 'xxx';
var password = 'yyy';
var endpoint = "https://webservice.s6.exacttarget.com/Service.asmx";
var custkey = 'Training Sergio'
var result;

payload += '<?xml version="1.0" encoding="utf-8"?>';
payload += '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
payload += '   <soap:Header>';
payload += '      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:mustUnderstand="1">';
payload += '         <wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">';
payload += '            <wsse:Username>' + username + '</wsse:Username>';
payload += '            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + password + '</wsse:Password>';
payload += '         </wsse:UsernameToken>';
payload += '      </wsse:Security>';
payload += '   </soap:Header>';
payload += '   <soap:Body>';
payload += '        <PerformRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI" xmlns:ns2="urn:fault.partner.exacttarget.com">';
payload += '            <Action>ClearData</Action>';                     
payload += '                <Definitions>';
payload += '                  <Definition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DataExtension">';
payload += '                     <CustomerKey>'+custkey+'</CustomerKey>';
payload += '                  </Definition>';
payload += '                </Definitions>';
payload += '        </PerformRequestMsg>';
payload += '   </soap:Body>';
payload += '</soap:Envelope>';

try {
    result = HTTP.Post(endpoint,"text/xml",payload,["SOAPAction"],["Perform"]);
} catch(e) { 
    result = {StatusCode:500,Response:Stringify(e)};
}

  if (result.StatusCode != 200) {
    //Bad response
    Write(Stringify(result));
} else {
    //Good response
    Write(Stringify(result));
}

</script>

This is the error that I am getting

{"StatusCode":200,"Response":["PerformResponseurn:uuid:6ac6d18f-dfc1-4239-93f4-0d6ecf4d8284urn:uuid:1d0a8836-e3e3-41ce-bb4f-4a9d616df0d8http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous2018-12-14T20:39:28Z2018-12-14T20:44:28ZErrorException occured during perform ClearData operation on DataExtension: 00000000-0000-0000-0000-000000000000, CustomerKey: ErrorID: 429699442Training SergioError5cad672d-9eb5-4485-8c68-25c95f491e71"]}

Also tried the the CLientID but that doesn't help either

<Client>
  <ID>ddd1257</ID>
</Client>
  • Is there a reason why you do it with standard POST request and not with SSJS API function? developer.salesforce.com/docs/… – Mateusz Bartkowiak Dec 15 '18 at 14:37
  • Yes. I have a requirement to clear out all the Data Extensions that exist in a particular business unit. The standard SSJS API function requires a DE field as a mandatory argument – Maneesh Dec 17 '18 at 5:07
  • From the error, it sounds like the DE you are specifying does not exist. Have you verified that you are A.) Using the proper authentication/permissions in the Child BU and B.) That the DE you are targeting actually exists in that BU. – Gortonington Dec 17 '18 at 14:05
  • @Maneesh - the Perform function in the link he provided does not require a field. It basically is a shortcut to the above. You can also check out WSProxy Perform, which will likely speed up both development as well as processing (developer.salesforce.com/docs/…) – Gortonington Dec 17 '18 at 14:07
3

I see that you were able to resolve your issue and I am glad to see that!

But I wanted to post a sample of WSProxy that I would highly recommend using in the future. The build you provided is inefficient not just in development and maintenance, but also in processing.

WSProxy is fairly new still so it is not well known or documented, but it is a huge improvement for SOAP API in SFMC and hopefully its abilities and 'power' continues to grow as time goes on.

<script runat="server">

custkey = 'Training Sergio'

//Set the BU you are targeting
api.setClientId({ "ID": ddd1257, "UserID": yourID });

// ID is Memeber ID
// UserID is the ID of the designated user for that BU


var prox = new Script.Util.WSProxy();
var action = "ClearData";
var props = {
    DataExtension: {
        CustomerKey: custkey
    }
};
var opts = {};
var data = prox.performItem("DataExtension", props, action, opts);

</script>
  • I tried your code but its givin me the following error: {"message":"Error executing perform call.","description":"ExactTarget.OMM.FunctionExecutionException: Error executing perform call.\r\n Error Code: OMM_FUNC_CONTEXT_ERR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nExactTarget.OMM.InvalidFunctionParameterException: Invalid property name: DataExtension\r\n Error Code: OMM_FUNC_CONTEXT_ERR\r\n - from OMMCommon\r\n\r\n\r\n\r\n"} – SebOB Feb 5 at 15:54
  • The issue was a copy/paste mistake in the object. I have now corrected it to "DataExtension" as it should have been. Thank you for bringing it to my attention that it was erroring. It now functions as expected. – Gortonington Aug 20 at 13:40
1

I was able to resolve it by placing the ClientID inside the Definition tag.

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


var payload = '';
var username = 'xxx';
var password = 'yyy';
var endpoint = "https://webservice.s6.exacttarget.com/Service.asmx";
var custkey = 'Training Sergio';
var result;
var ClientID = '12345'; 

payload += '<?xml version="1.0" encoding="utf-8"?>';
payload += '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
payload += '   <soap:Header>';
payload += '      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:mustUnderstand="1">';
payload += '         <wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">';
payload += '            <wsse:Username>' + username + '</wsse:Username>';
payload += '            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + password + '</wsse:Password>';
payload += '         </wsse:UsernameToken>';
payload += '      </wsse:Security>';
payload += '   </soap:Header>';
payload += '   <soap:Body>';
payload += '        <PerformRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI" xmlns:ns2="urn:fault.partner.exacttarget.com">';
payload += '            <Action>ClearData</Action>';                     
payload += '                <Definitions>';
payload += '                  <Definition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DataExtension">';
payload += '                   <Client>';  
payload += '                    <ID>'+clientID+'</ID>'; 
payload += '                   </Client>'; 
payload += '                     <CustomerKey>'+custkey+'</CustomerKey>';
payload += '                  </Definition>';
payload += '                </Definitions>';
payload += '        </PerformRequestMsg>';
payload += '   </soap:Body>';
payload += '</soap:Envelope>';

try {
    result = HTTP.Post(endpoint,"text/xml",payload,["SOAPAction"],["Perform"]);
} catch(e) { 
    result = {StatusCode:500,Response:Stringify(e)};
}

  if (result.StatusCode != 200) {
    //Bad response
    Write(Stringify(result));
} else {
    //Good response
    Write(Stringify(result));
}

</script>
0

I was able to clear a data extension, this code is based on Gorgontington's previus answer which was giving me the error: {"message":"Error executing perform call.","description":"ExactTarget.OMM.FunctionExecutionException: Error executing perform call.\r\n Error Code: OMM_FUNC_CONTEXT_ERR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nExactTarget.OMM.InvalidFunctionParameterException: Invalid property name: DataExtension\r\n Error Code: OMM_FUNC_CONTEXT_ERR\r\n - from OMMCommon\r\n\r\n\r\n\r\n"} The code that worked for me is:

 <script runat="server">
Platform.Load("Core","1");
var api = new Script.Util.WSProxy();

var action = "ClearData";
var props = {  
        CustomerKey: 'THE_DATAEXTENSION_CUSTOMERKEY'
};
var opts = {};

try{
    var data = api.performItem("DataExtension", props, action, opts);
    //Write(Stringify(data));
}catch(ex){
    //Write(Stringify(ex));
}

  • Confirmed this example is working, thanks Seb! – Doug Jul 9 at 10:51
  • 1
    I do not see the value that was added here. the only change was that I had the incorrect object in my answer (copy/paste mistake) - otherwise your code is identical to mine. This would have been a good place to either edit my answer to replace it with the correct object or place the call out in the comments rather than create a new answer which does not explain why yours works and mine did not - only saying mine threw an error. I do appreciate the correction, but I am not sure this was the correct way to go about it for such a minor mistake. – Gortonington Aug 20 at 13:39
  • 1
    Also, this does not resolve the OPs original request as it is BU specific (as WSProxy is by default) and does not allow for access to other BUs via ClientID, which is what the OP wanted. – Gortonington Aug 20 at 13:43

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.