cancel
Showing results for 
Search instead for 
Did you mean: 

How to prevent Contact Validate script from being executed twice?

Former Member
0 Kudos

We have added a script on Contact class (Class 600, Target Validated) which calls a third-party webservice to do some validations and create the user id of the new contact. Since user id (DB field name is NAME) is a unique field in Contact table, I had to write this script in Validated phase itself (before the contact record is saved in database). This contact validate script is working fine.

Now when a Supplier Registration is approved (from Supplier Management -> Registration -> Supplier Registration List, select a pending registration and approve), the user is taken to Create New Supplier screen. Here the primary contact details of the new supplier are already present (populated from details entered in registration form). If we just click Save button on this screen, the Contact Validate script is getting executed twice. This is the entry in log:

##sap.com/E-Sourcing-Server#C000CF8242BA0E3C0000002100000AD4#2174850000000004#sap.com/E-Sourcing-Server#E-Sourcing.eso.java.com.sap.odp.comp.scripting.ScriptManager.markLog#VAC53324#48##45CE2E8DDC2411E38616000000212F82#893b16f1dc2411e3985c000000212f82#893b16f1dc2411e3985c000000212f82#0#Thread[RequestHandler.RqThread: fullsave,5,Dedicated_Application_Thread]#Plain##

Facility=local4;sessionid=38266bf0e25b54b7b7ea2eed474d1b4749c44280;tenantid=\#xxx_context#;username=xxx;begin: executeDocumentEventScript for VALIDATE on null#

...............here debug logs from Call to the script written on Contact class, involves logic to call web service and create user id ..

#2.0 #2014 05 15 11:32:55:593#+00#Info#/Applications/E-Sourcing/eso#

##sap.com/E-Sourcing-Server#C000CF8242BA0E3C0000014D00000AD4#2174850000000004#sap.com/E-Sourcing-Server#E-Sourcing.eso.java.com.sap.odp.comp.scripting.ScriptManager.markLog#VAC53324#48##45CE2E8DDC2411E38616000000212F82#893b16f1dc2411e3985c000000212f82#893b16f1dc2411e3985c000000212f82#0#Thread[RequestHandler.RqThread: fullsave,5,Dedicated_Application_Thread]#Plain##

Facility=local4;sessionid=38266bf0e25b54b7b7ea2eed474d1b4749c44280;tenantid=\#xxx_context\#;username=xxx;begin: executeDocumentEventScript for VALIDATE on VENCON-0000067#


The first call to script creates the user id via web services and the second call fails because create is called again for an existing user. Can anyone please help me out - how can I prevent this second call from happening?


Accepted Solutions (1)

Accepted Solutions (1)

former_member89217
Contributor
0 Kudos

It would seem relying on the validate hook to "create" something is a bit tricky since as you see it can be created only once.  If you must use this hook you will need logic to test for prior creation before allowing the creation call to be made.

Gary

Former Member
0 Kudos

Hi Gary,

If user is already created, it is an error as per our requirement. So the logic to check if user is created is there and that is the place where error is thrown during Supplier registration approval.

I tried checking the phase variable but that came as null (phase_advancing, current_phase, other_phase are all null in my script)

Then I tried writing the script on these other targets also:

1. Created - the script got called when I clicked Add button in Contacts tab itself (before I could enter contact name, email etc which i need for calling web service)

2. Loaded - the sample script did not get called at all!

2. Saved - script got called but it did not let me update the User ID field. User ID maps to NAME db field which has a unique constraint

The other Target options like Duplicated, pre/post phase change, publish etc are not applicable for my requirement

Can you please suggest some alternate Target for this script?

Gayathri

former_member89217
Contributor
0 Kudos

Have you tried the field validation target?  Maybe on the name field itself?

Gary

Former Member
0 Kudos

Hi Gary,

I did not try Field Validation since I was able to find one logic for checking user creation in Validate itself. Before creating new user, I have to send a Search web request to verify if the user already exists in the 3rd party system. For search, the input parameter is the Email. I am checking the response from Search method and if User ID of existing user matches the User ID on screen then this is second execution of same script by Supplier Validate event.. hence i am logging that info and skipping rest of the logic

Answers (0)