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

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

Avatar

Avatar
Ignite 1
Level 1
christopherp496
Level 1

Likes

3 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Validate 1
Boost 3
Boost 1
View profile

Avatar
Ignite 1
Level 1
christopherp496
Level 1

Likes

3 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Validate 1
Boost 3
Boost 1
View profile
christopherp496
Level 1

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)

Avatar

Avatar
Validate 1
MVP
kapilKochar
MVP

Likes

128 likes

Total Posts

140 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Contributor
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Validate 1
MVP
kapilKochar
MVP

Likes

128 likes

Total Posts

140 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Contributor
Give Back 10
Give Back 5
Give Back 3
View profile
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)

Avatar

Avatar
Ignite 1
Level 1
christopherp496
Level 1

Likes

3 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Validate 1
Boost 3
Boost 1
View profile

Avatar
Ignite 1
Level 1
christopherp496
Level 1

Likes

3 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Validate 1
Boost 3
Boost 1
View profile
christopherp496
Level 1

16-05-2019

Thank You!

Avatar

Avatar
Validate 1
Level 4
pierrec70731455
Level 4

Likes

62 likes

Total Posts

59 posts

Correct Reply

14 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 4
pierrec70731455
Level 4

Likes

62 likes

Total Posts

59 posts

Correct Reply

14 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
pierrec70731455
Level 4

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