Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

How to get an id of a newly inserted recipient in JavaScript

Avatar

Level 2

Hello,

How do you get a recipient id immediately after it was inserted using xtk.session.write?

Example

xtk.session.Write(<recipient _operation="insert" lastName="Martinez" firstName="Peter" xtkschema="nms:recipient"/>);

//How to get the id of this newly added record?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi ,

If you want to use newly created row ID just after creating a record  then I will suggest you to use second way to create records i.e usinf create method.

var object = namespace.schemaName.create( <schemaName    col1 = {"value1"}    col2 = {"value2"}   /> );

object.save();

logInfo(" Id of latest added record is "+ object["id"]);

Thanks,

Kapil

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi ,

If you want to use newly created row ID just after creating a record  then I will suggest you to use second way to create records i.e usinf create method.

var object = namespace.schemaName.create( <schemaName    col1 = {"value1"}    col2 = {"value2"}   /> );

object.save();

logInfo(" Id of latest added record is "+ object["id"]);

Thanks,

Kapil

Avatar

Level 5

Hi,

to complete kapscool's response, I don't think you get the rowid but THE (recipient) id with his method

var recipient= nms.recipient.create( <schemaName    lastName= {"Martinez"}    firstName= {"Peter"}  /> );

recipient.save();

logInfo(" Id of latest recipient added is "+ recipient["id"]);

You can also use the NLWS create method (doc) :

var recipient= NLWS.nmsRecipient.create(

          {recipient: {

            lastName: "Martinez",

            firstName: "Peter"

            }});

recipient.save();

logInfo(" Id of latest recipient added is " + recipient.id);

Kind regards,

Pierre