0

Does anyone know how to Update ActiveFlag Using WS Proxy?

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

try {
    var prox = new Script.Util.WSProxy();
    var cols = ["ID", "Name", "ActiveFlag"];

    // Replace with the name and key of your data extension
    var deName = "For_Deactivation_User_DE";
    var deKey = "";

    var de = DataExtension.Init(deKey);

    // Retrieve all the rows from the data extension
    var data = de.Rows.Retrieve();

    for (var i = 0; i < data.length; i++) {
        var email = data[i].EmailAddress;

        // Filter the AccountUser records based on the UserId field
        var filter = {
            Property: "Email",
            SimpleOperator: "equals",
            Value: email
        };

        var accountUsers = prox.retrieve("AccountUser", cols, filter);

        for (var j = 0; j < accountUsers.Results.length; j++) {
            var accountUser = accountUsers.Results[j];
            accountUser.ActiveFlag = false;

            // Update the AccountUser record
            var updateResponse = prox.updateItem("AccountUser", accountUser);
            Write("Account User " + accountUser.Email + " ActiveFlag property was updated to false.");
        }
    }
} catch (ex) {
    Write("An error has occurred: " + Stringify(ex));
}
I used this code but I receive this below error.

An error has occurred: {"message":"Error executing update call.","description":"ExactTarget.OMM.FunctionExecutionException: Error executing update 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: Property: UserPermissions is an array but value to be set was not an array.\r\n Error Code: OMM_FUNC_CONTEXT_ERR\r\n - from OMMCommon\r\n\r\n\r\n\r\n"}

Please help.

1 Answer 1

1

First of all, you cannot simply use the results from AccountUser retrieval to execute further updates of the same AccountUser. You have to change the format of the values as well. You can check out this answer for better understanding.

Then, once you would adjust the format for the update, you would hit the same wall of "User [n] does not have permission to edit ACCOUNTUSERS on account [MID]" that is actually still not fixed, even though SF says it is. This eliminates any usage of WSProxy with Create and Update method on AccountUser object.

Therefore, you need to prepare a SOAP envelope to update your user and execute the API call. The logic you would need:

  1. Find the AccountUsers by their email (this part you already have) and retrieve the AccountUserIDs and MIDs (Client.ID) they belong to.
  2. Retrieve an Access Token
  3. For each separate user do a SOAP call via HTTP.Post SSJS function where you have to specify AccountUserID and MID as identifiers and also ActiveFlag = false to switch off the user
<script language="javascript" runat="server">
Platform.Load("Core", "1")

// Required variables for the code
var Domain = "";
var AccessToken = "";
var MID = "";
var AccountUserID = "";

var URL = 'https://' + Domain + '.soap.marketingcloudapis.com/Service.asmx';
var ContentType = 'text/xml';

var Payload = '';
Payload +=  '<?xml version="1.0" encoding="UTF-8"?>';
Payload +=  '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">';
Payload +=      '<s:Header>';
Payload +=          '<a:Action s:mustUnderstand="1">Create</a:Action>';
Payload +=          '<a:To s:mustUnderstand="1">https://' + Domain + '.soap.marketingcloudapis.com/Service.asmx</a:To>';
Payload +=          '<fueloauth xmlns="http://exacttarget.com">' + AccessToken + '</fueloauth>';
Payload +=      '</s:Header>';
Payload +=      '<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
Payload +=          '<CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">';
Payload +=              '<Options>';
Payload +=                  '<SaveOptions>';
Payload +=                      '<SaveOption>';
Payload +=                          '<PropertyName>*</PropertyName>';
Payload +=                          '<SaveAction>UpdateAdd</SaveAction>';
Payload +=                      '</SaveOption>';
Payload +=                  '</SaveOptions>';
Payload +=              '</Options> ';
Payload +=              '<Objects xsi:type="AccountUser">';
Payload +=                  '<PartnerKey xsi:nil="true"></PartnerKey>';
Payload +=                  '<ObjectID xsi:nil="true"></ObjectID>';
Payload +=                  '<Client>';
Payload +=                      '<ID>' + MID + '</ID>'; // Paste MID
Payload +=                  '</Client>';
Payload +=                  '<AccountUserID>' + AccountUserID + '</AccountUserID>'; // Paste AccountUserID
Payload +=                  '<ActiveFlag>false</ActiveFlag>';
Payload +=              '</Objects>';
Payload +=          '</CreateRequest>';
Payload +=      '</s:Body>';
Payload +=  '</s:Envelope>';

var HttpPost = HTTP.Post(URL, ContentType, Payload);
</script>

You must log in to answer this question.

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