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

christopherp496

15-05-2019

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?

Accepted Solutions (1)

Accepted Solutions (1)

kapilKochar

MVP

15-05-2019

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

Answers (2)

Answers (2)

pierrec70731455

16-05-2019

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