3

(Title Translation via Google Translate: I want to be able to retrieve and update _EnterpriseAttributes fields from a subscriber)

deseo poder recuperar y actualizar los campos de _EnterpriseAttributes de un suscriptor, es decir los campos de usuario y sus atributos, los campos de _Subscribers los estoy trayendo mediante un objecto, pero no he podido traer los de _EnterpriseAttributes, o como puedo hacer para poder actualizar los atributos de un suscriptor? actualmente traigo los datos del suscriptor de la siguiente manera

Google Translate English:

I want to be able to retrieve and update the _EnterpriseAttributes fields of a subscriber, that is to say the user fields and their attributes, the _Subscribers fields I am bringing them through an object, but I have not been able to bring those of _EnterpriseAttributes, or how can I do to update the attributes of a subscriber? I currently bring the subscriber data as follows

 /* Crear el objeto del subscriptor */
  set @subscriber = CreateObject( "Subscriber" )
  SetObjectProperty( @subscriber, "EmailAddress", @subKey )
  SetObjectProperty( @subscriber, "SubscriberKey", @subKey )

        /* Get all the subscriber attributes */
        SET @rr2 = CreateObject("RetrieveRequest")
        SetObjectProperty(@rr2,"ObjectType","Subscriber")
        AddObjectArrayItem(@rr2, "Properties", "SubscriberID")
        AddObjectArrayItem(@rr2, "Properties", "DateUndeliverable")
        AddObjectArrayItem(@rr2, "Properties", "DateJoined")
        AddObjectArrayItem(@rr2, "Properties", "DateUnsubscribed")
        AddObjectArrayItem(@rr2, "Properties", "Domain")
        AddObjectArrayItem(@rr2, "Properties", "EmailAddress")
        AddObjectArrayItem(@rr2, "Properties", "BounceCount")
        AddObjectArrayItem(@rr2, "Properties", "SubscriberKey")
        AddObjectArrayItem(@rr2, "Properties", "SubscriberType")
        AddObjectArrayItem(@rr2, "Properties", "Status")
        AddObjectArrayItem(@rr2, "Properties", "Locale")
        
        

        /* Create a filter be the subscriber Id */
        SET @sfp2 = CreateObject("SimpleFilterPart")
        SetObjectProperty(@sfp2,"Property","SubscriberKey")
        SetObjectProperty(@sfp2,"SimpleOperator","equals")
        AddObjectArrayItem(@sfp2,"Value",@subKey)
       
       
        
        SetObjectProperty(@rr2,"Filter",@sfp2)
        SET @sub_rowset = InvokeRetrieve(@rr2, @rrStatus, @rrRequestID)
        



output(concat("rrStatus: ", @rrStatus))
output(concat("<br>rrRequestID: ", @rrRequestID))


        IF ROWCOUNT(@sub_rowset) == 1 THEN
            SET @sub_row = ROW(@sub_rowset,1)
            SET @sk = FIELD(@sub_row,"SubscriberKey")
            SET @x = FIELD(@sub_row,"Status")
            SET @z = FIELD(@sub_row,"EmailAddress")


            OutputLine(CONCAT("SubscriberKey: ",V(@sk),"<br />"))
            OutputLine(CONCAT("Status: ",V(@x),"<br />"))
            OutputLine(CONCAT("email: ",V(@z),"<br />"))
            
               
        ENDIF  
          
          
          
    ]%%

pero cuando le agrego AddObjectArrayItem(@rr2, "Properties", "Attributes") me sale el siguiente error:
rrStatus: Error: The Request Property(s) Attributes do not match with the fields of Subscriber retrieve

Google Translate English:

but when I add AddObjectArrayItem (@ rr2, "Properties", "Attributes") I get the following error:
rrStatus: Error: The Request Property(s) Attributes do not match with the fields of Subscriber retrieve

2
  • 5
    Bienvenidos a Salesforce Stack Exchange. La idioma de esto sitio es Inglés. ¿Puede traducir su puesto? (Lo siento por mi Español).
    – David Reed
    Jul 1, 2020 at 15:58
  • Agregué una versión solo de AMPscript en mi respuesta para usted según lo solicitado Jul 1, 2020 at 20:08

1 Answer 1

3

Unfortunately, the Attributes part of the SOAP Object Subscriber is not retrievable, see below snippet from a Describe call to the object:

Desafortunadamente, la parte de Atributos del objeto SOAP Subscriber no se puede recuperar, consulte el fragmento a continuación de una llamada de Describe al objeto:

<Properties>
  <PartnerKey xsi:nil="true" />
  <ObjectID xsi:nil="true" />
  <Name>Attributes</Name>
  <DataType>Attribute[]</DataType>
  <IsUpdatable>true</IsUpdatable>
  <IsRetrievable>false</IsRetrievable>
</Properties>

but oddly enough, if you filter by Subscriberkey and retrieve the property of ID from the Object, it will actually return them automatically (see below sample envelope):

pero por extraño que parezca, si filtra por Subscriberkey y recupera la propiedad de ID del Objeto, en realidad los devolverá automáticamente (vea el sobre de muestra a continuación):

         <RetrieveRequest>
            <ClientIDs>
               <ClientID>1234567</ClientID>
            </ClientIDs>
            <ObjectType>Subscriber</ObjectType>
            <Properties>CreatedDate</Properties>
            <Properties>Client.ID</Properties>
            <Properties>EmailAddress</Properties>
            <Properties>SubscriberKey</Properties>
            <Properties>Status</Properties>
            <Properties>UnsubscribedDate</Properties>
            <Properties>EmailTypePreference</Properties>
            <Properties>ID</Properties>
            <!--This makes Profile Attributes show in the Results-->
            <Filter xsi:type="ns1:SimpleFilterPart" xmlns:ns1="http://exacttarget.com/wsdl/partnerAPI">
               <Property>SubscriberKey</Property>
               <SimpleOperator>equals</SimpleOperator>
               <Value>example@email.com</Value>
            </Filter>
            <QueryAllAccounts>false</QueryAllAccounts>
         </RetrieveRequest>

which will return the Attributes as a nested rowset.

que devolverá los atributos como un conjunto de filas anidado.

                <Attributes>
                    <Name>First Name</Name>
                    <Value>Gor</Value>
                </Attributes>
                <Attributes>
                    <Name>Last Name</Name>
                    <Value>Tonington</Value>
                </Attributes>
                <Attributes>
                    <Name>Region</Name>
                    <Value />
                </Attributes>
                <Attributes>
                    <Name>Country Code</Name>
                    <Value />
                </Attributes>

I personally would recommend doing this instead inside of WSProxy for faster processing as well as easier parsing and less code than AMPScript:

Personalmente, recomendaría hacer esto en lugar de WSProxy para un procesamiento más rápido, así como un análisis más fácil y menos código que AMPScript:

<script runat="server">

Platform.Load("Core","1.1.1");
  var subscriberkey = "example@email.com"

  var prox = new Script.Util.WSProxy();

  var cols = ["CreatedDate","Client.ID","EmailAddress","SubscriberKey","Status","UnsubscribedDate","EmailTypePreference","ID"];
  var filter = {
      Property: "SubscriberKey",
      SimpleOperator: "equals",
      Value: subscriberkey
  };
  var res = prox.retrieve("Subscriber", cols, filter);

</script>

Which will return:

Que volverá:

[
    {
        "SubscriberKey": "example@email.com",
        "EmailAddress": "example@email.com",
        "Status": "Active",
        "Attributes": [
            {
                "Name": "First Name",
                "Value": "Gor",
                "Compression": null
            },
            {
                "Name": "Last Name",
                "Value": "Tonington",
                "Compression": null
            },
            {
                "Name": "Region",
                "Value": "",
                "Compression": null
            },
            {
                "Name": "Country Code",
                "Value": "",
                "Compression": null
            }
        ],
        "ID": XXXXXXXXXX,
        "EmailTypePreference": "HTML"
    }
]

(I abbreviated it some to save space)

You can then get the values from this array by the following:

(Lo abrí un poco para ahorrar espacio)

Luego puede obtener los valores de esta matriz de la siguiente manera:

var LastName = res.Attributes[0].Value; which would output as: Tonington

var LastName = res.Attributes [0] .Value; que se generaría como: Tonington


EDIT

If it absolutely positively needs to be in AMPScript, the below should show you how to collect it and parse it:

EDITAR

Si es absolutamente necesario que esté en AMPScript, el siguiente debe mostrarle cómo recopilarlo y analizarlo:

%%[
 set @subKey = "example@email.com"

 /* Crear el objeto del subscriptor */
  set @subscriber = CreateObject( "Subscriber" )
  SetObjectProperty( @subscriber, "EmailAddress", @subKey )
  SetObjectProperty( @subscriber, "SubscriberKey", @subKey )

        /* Get all the subscriber attributes */
        SET @rr2 = CreateObject("RetrieveRequest")
        SetObjectProperty(@rr2,"ObjectType","Subscriber")
        AddObjectArrayItem(@rr2, "Properties", "EmailAddress")
        AddObjectArrayItem(@rr2, "Properties", "SubscriberKey")
        AddObjectArrayItem(@rr2, "Properties", "ID")

        /* Create a filter be the subscriber Id */
        SET @sfp2 = CreateObject("SimpleFilterPart")
        SetObjectProperty(@sfp2,"Property","SubscriberKey")
        SetObjectProperty(@sfp2,"SimpleOperator","equals")
        AddObjectArrayItem(@sfp2,"Value",@subKey)      
        
        SetObjectProperty(@rr2,"Filter",@sfp2)
        SET @sub_rowset = InvokeRetrieve(@rr2, @rrStatus, @rrRequestID)
        
        output(concat("rrStatus: ", @rrStatus,"<br>"))
        output(concat("<br>rrRequestID: ", @rrRequestID,"<br>"))

        IF ROWCOUNT(@sub_rowset) == 1 THEN
            SET @sub_row = ROW(@sub_rowset,1)
            SET @sk = FIELD(@sub_row,"SubscriberKey")
            SET @x = FIELD(@sub_row,"Status")
            SET @z = FIELD(@sub_row,"EmailAddress")
            SET @a = FIELD(@sub_row,"Attributes")

            OutputLine(CONCAT("SubscriberKey: ",V(@sk),"<br />"))
            OutputLine(CONCAT("Status: ",V(@x),"<br />"))
            OutputLine(CONCAT("email: ",V(@z),"<br />"))
            OutputLine(CONCAT("Attributes: ",V(@a),"<br />"))

        SET @aRC = RowCount(@a)
            
        FOR @i=1 TO @aRC DO
           SET @aRow = ROW(@a,@i)
           SET @Name = FIELD(@aRow,"Name")
           SET @Value = FIELD(@aRow,"Value")
           OutputLine(CONCAT(@Name, ": ", @Value,"<br />"))
               
        NEXT @i
        ENDIF           
          
    ]%%

To gather it, you add in the ID property:

Para recopilarlo, agregue la propiedad ID:

AddObjectArrayItem(@rr2, "Properties", "ID")

and to parse, you do it in a for loop like so:

y para analizar, lo haces en un bucle for así:

        SET @a = FIELD(@sub_row,"Attributes")

        OutputLine(CONCAT("SubscriberKey: ",V(@sk),"<br />"))

        SET @aRC = RowCount(@a)
            
        FOR @i=1 TO @aRC DO
           SET @aRow = ROW(@a,@i)
           SET @Name = FIELD(@aRow,"Name")
           SET @Value = FIELD(@aRow,"Value")
           OutputLine(CONCAT(@Name, ": ", @Value,"<br />"))
               
        NEXT @i
9
  • perfect!! thank you very much. if i need to update each attribute independently i could save it in a different variable for each attribute? or there is some function to update these attributes independently thank you very much for the help Jul 1, 2020 at 20:21
  • 1
    My recommendation would be to do something like IF @Name == "FirstName" THEN SET @FirstName = @Value ENDIF etc.. There are some more complex stuff that can be done to do this more dynamically/elegant, but that might be too much for what you need. Jul 1, 2020 at 20:24
  • I will try to save the value of each attribute by means of the IF clause. Thank you very much for your help, friend Jul 1, 2020 at 21:20
  • 1
    @JeferssonGomez You could do something like: set @FirstName = Field(ROW(@aRC,1),"Value") and then second one would be: set @LastName = Field(ROW(@aRC,2),"Value") but then you are also depending on the ordinal value of the columns. If someone changes the order, it will completely screw up your script. Jul 2, 2020 at 12:47
  • 1
    Ok, thank you very much for your help. Jul 2, 2020 at 14:06

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.