cancel
Showing results for 
Search instead for 
Did you mean: 

How to access the ID of a PurchaseOrder before saving it?

georgk
Participant
0 Kudos

Dear community,

I need to implement a REST call to an external system passing through some data of PurchaseOrders.

The PurchaseOrders are part of a third-party process and created automatically by ByD from released SalesOrders.

The PurchaseOrders are created and automatically sent by ByD and afterwards saved by the system. The problem I'm facing is that at the time of the calls to AfterModify and BeforeSave, the ID field of the PO is not yet set.

Is there a way to get the ID in the AfterModify or BeforeSave before the PO is saved for the first time?

The only possible solution I came up with is to use internal communication to create an object. This message would be sent after the save and with the ID of the PO. Is another way to do it?

Thanks for your help and best regards,

Georg

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

the ID will be generated only after the first save. Only the uuid is available before.

You can create a MDR in order to process the created sales orders after the initial save.

georgk
Participant
0 Kudos

Hi,

thanks for the hint! The call to the external system should be executed right after the Purchase Order was created, therefore MDRs are not really an option...

I guess the internal communication wasn't such a bad solution after all

Best regards,

Georg

Former Member
0 Kudos

Hi Georg, what is you requirement? When you call the REST ws, what this ws will do? Why you need the ID?

georgk
Participant
0 Kudos

Hi Alessandro,

the REST service calls an external system to register the PO. The ID to identify POs in the external system and ByD should by identical which is why I need to know the ID. Furthermore, the PO should be posted to the external system almost immediately - so a mass data run is not really an option.

Thanks and best regards,

Georg

Former Member
0 Kudos

What about if you schedule a MDR every 5 minutes?

georgk
Participant
0 Kudos

That would work - but have you tried to schedule a MDR for every 5 minutes 24 hours a day?

The shortest recurrence period for a single MDR schedule is "once per day". That means you would have to manually create 60 / 5 = 12 schedules per hour, resulting in 12 * 24 = 288 schedule entries.

Former Member
0 Kudos

Yes. We did something similar for another business requirement and is working, regardless the large amount of schedulations.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Try with Number ranges, There are Function Modules available to get the next available PO Number

Jacques-Antoine
Active Participant
0 Kudos

Hello Georg,

I do not know if you can implement this in a REST call, but you can access data which is not yet stored in the database with the Retrieve() function.

A query only queries what is saved in the database, so after the Save is done.

However, with the Retrieve(), you can find a Purchase Order with its ID, for example, before the Save is done.

I often use this function myself in Before-Save events. The after modify shouldn't be a problem as the instance already exists if you can modify it.

I hope this can help you!


Best regards!

Have a nice day.

Jacques-Antoine

georgk
Participant
0 Kudos

Hi Jacques-Antoine,

When the PurchaseOrder is created, my AfterModify / BeforeSave actions get called - so I have the BO instance of the PurchaseOrder that I need to do the REST-call stored in the "this" reference and as you state, I can modify it.

However, as this object is not yet stored it doesn't have an ID.

Do you mean that by calling the Retrieve() Function (e.g. var instance = PurchaseOrder.Retrieve(this.UUID); ) the system will set the ID?

Jacques-Antoine
Active Participant
0 Kudos

Hello Georg,

I will try it myself to check if this can work.

I will get back to you as soon as I tested this out.

Best regards.

Jacques-Antoine