Expand my Community achievements bar.

SOLVED

nmsGroup.Register how to implement

Avatar

Community Advisor

Hello,

i am struggling to implement nmsGroup.Register(xml recipientlist)


Does anybody know what format it takes there is nothing in documentation:

https://experienceleague.adobe.com/developer/campaign-api/api/sm-group-Register.html?hl=register

 

Workaround was to use another function from recipient schema:

https://experienceleague.adobe.com/developer/campaign-api/api/sm-recipient-RegisterGroup.html?hl=reg...

 

 

//List
var entity = <entityList><key value="24447964"/>
              <where>
                <condition enabledIf="" expr="@id = 24447964"/>
              </where>
            </entityList>
 
//Recipient
var choice = <choiceList><key value="18995462"/>
              <where>
                <condition enabledIf="" expr="@id = 18995462"/>
              </where>
            </choiceList>
nms.recipient.RegisterGroup(entity,choice,true)

 

 

I am wondering if i have to use something similar to this. Anyway little more documentation would be nice to have.

 

Any advice will be appreciated

Marcel

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @Tobias_Lohmann ,

yes I can do that.. I thought i could use the ootb methods.

I do this for now. Which uses RegisterGroup but i only Register one recipient at a time. No idea if i can add multiple at a time or how

//some loop 
for (;;;){
choiceList.push({value :recipient.id});
where.push({condition : {expr: '@id=' + recipient.id}});
}
var id = 1111;//group id
for (var i = 0; i<this.where.length;i++) NLWS.nmsRecipient.RegisterGroup( DOMDocument.fromJXON({'entityList' : { key: {value : id}, where : {condition : {expr : '@id='+id}}}}), DOMDocument.fromJXON({'choiceList' : { key: choiceList[i], where : where[i]}}), true );

I guess.. i will just directly insert them to the rcpGrpRel with session write. thanks a lot for your help.

 

Marcel

 

View solution in original post

6 Replies

Avatar

Employee Advisor

Hi Marcel,

 

I saw your post and did some investigation. Unfortunately I didn't find a real solution, but here are my observations:

 

1. you can see the method signature in the data schema nms:group:

<method library="nms:group.js" name="Register" pkonly="true">
  <help>Add one or more records to the list</help>
  <parameters>
    <param desc="List of records to add" name="recipientList" type="DOMElement"/>
  </parameters>
</method>

It expects a DOMElement kind of object for recipient list.

 

2. the actual method code can be seen in nms:group.js under Javascripts. The method name is nms_group_Register.

 

3. Looking at the code you can see it will only execute for groups type 1 or 2; looking at the data schema again this means only for groups that are of type "File" (upload) or "List" (eg. Audience Manager Segment). Regular recipients lists (type 0, "Group") are not supported by this method.

 

4. In the code there is a loop over the provided recipient list object (remember: a DOMElement object):

for each( var eSelected in eRecipientList.data.* )

 The eRecipientList.data.* is not working (at least in my tests), because there is no data attribute in the DOMElement class.

 

5. I tried to craft an XML structure that has a root node named "data", but this doesn't work:

var group = nms.group.load(<the group id>);
var recipients = DOMDocument.fromXMLString('<data><recipient firstName="Tobias" lastName="Lohmann" email="<email address>"/></data>');
group.Register(recipients.root); // the ".root" to get the DOMElement object

So unfortunately no solution for you. It seems the DOMCharacterData class has a "data" attribute, but this represents only the text content of a node. So you might be able to provide the recipient list as a CDATA object inside a DOMElement.

 

... or you use the workaround you already figured out. 

... or as another workaround you could add the recipient per code to the nms:rcpGrpRel schema

 

I hope this gives you a bit more insights to work with.

 

Best regards, Tobias

Avatar

Community Advisor

Hello Tobias,

thanks a lot this gave me some hints.. i totally forgot that i can explore these methods in the javascripts foders 

Avatar

Community Advisor

I have checked the JS and it is used for list type list and file.. also it has 2 arguments.. so the method might be defined somewhere else?

 

Also the workaround i have no idea how to add multiple recipients? can we figure that one out.. i tried many combinations and none works.. if i find something on both i will share


@Jonathon_wodnicki

Avatar

Employee Advisor

Yes, the method takes two parameters, but the first is the reference to the group object itself; you only need to provide the recipient list parameter, as declared in the method signature.

You could add recipients to a list per code like so: 

var groupId = 499360; // the group id
var recipientIds = [5585, 53239]; // recipient ids as array
var collection = <rcpGrpRel-collection xtkschema="nms:rcpGrpRel"/>;

for each (var recipientId in recipientIds) {
  var collectionItem = <rcpGrpRel xtkschema="nms:rcpGrpRel" _key="@group-id,@recipient-id" group-id={groupId} recipient-id={recipientId}/>;
  collection.appendChild(collectionItem);   
}

xtk.session.WriteCollection(collection);

Avatar

Correct answer by
Community Advisor

Hello @Tobias_Lohmann ,

yes I can do that.. I thought i could use the ootb methods.

I do this for now. Which uses RegisterGroup but i only Register one recipient at a time. No idea if i can add multiple at a time or how

//some loop 
for (;;;){
choiceList.push({value :recipient.id});
where.push({condition : {expr: '@id=' + recipient.id}});
}
var id = 1111;//group id
for (var i = 0; i<this.where.length;i++) NLWS.nmsRecipient.RegisterGroup( DOMDocument.fromJXON({'entityList' : { key: {value : id}, where : {condition : {expr : '@id='+id}}}}), DOMDocument.fromJXON({'choiceList' : { key: choiceList[i], where : where[i]}}), true );

I guess.. i will just directly insert them to the rcpGrpRel with session write. thanks a lot for your help.

 

Marcel

 

Avatar

Level 4

Super late reply, but adding this comment for anyone else who might be struggling with this API, googling it and coming across this forum post (like me) 

I was able to get the .register() function working with the following:

var listId = 11122223333 (obviously just get your list primary key)
var recipientId = 12345678 (get your recipient Id from whereever)

var listObj = NLWS.nmsGroup.load(listId);

listObj.Register(
<recipientList>
<data>
<recipient id={recipientId}>
</recipient>
</data>
</recipientList>
)

 

And I was able to get custom fields set with:

 

var listId = 11122223333 (obviously just get your list primary key)
var recipientId = 12345678 (get your recipient Id from whereever)

var now = formatDate(getCurrentDate(),"%4Y/%2M/%2D %02H:%02N:%02S")

var listObj = NLWS.nmsGroup.load(listId);

listObj.Register(
<recipientList>
<data>
<recipient id={recipientId}>
<registerDate>{now}</registerDate>
</recipient>
</data>
</recipientList>
)