Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

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

christopherp496
Level 2
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
kapilKochar
Correct answer by
Community Advisor
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
kapilKochar
Correct answer by
Community Advisor
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

pierrec70731455
Level 5
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