cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to modify a Contact's user ID through scripting

Former Member
0 Kudos

Hi,

I am new to scripting and am facing the following issue in a Script Definition. In Supplier Management screen of Sourcing, when a business user creates a new Contact for a supplier, I need to replace the contact's user ID with another value. This is the code snippet that I tried:

currentRec = doc.getObjectReference();

contactHome = (ContactIBeanHomeIfc)IBeanHomeLocator.lookup(session, ContactIBeanHomeIfc.sHOME_NAME);

contact = contactHome.find(currentRec);

.. some more lines of code to print out the contact first name, user ID etc which worked fine..

contact.setName("Hello123");

This script gave the following inline script evaluation error while saving the contact:

Error executing script: Sourced file: inline evaluation of: ``import com.sap.odp.api.ibean.*; import com.sap.odp.api.ibean.common.*; import . . . '' : Method Invocation contact.setName.

The script definition is for Class 600 - Contact. I checked the Reference Guide and found that User ID display field in UI is mapped to database field NAME and the corresponding getter/setter methods in the bean are getName and setName.. getName() gives me the user ID that the user enters while creating the record. But when I try to modify that value in a pre-save script using the above code I am getting this error..

Can anyone please help me out? Why is Sourcing not letting me call the setName() method?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Can you please explain the need for replacing the contact, i do not think system will allow to change the user id of the current contact, what you can do is if you do not need the previous contact then inactivate it and create a new one.

Former Member
0 Kudos

Hi Dhiraj,

My requirement is to replace the User ID with a value generated from another system. Currently when a buyer creates a contact, he/she types in a user id that gets saved in sourcing. Before the contact record is saved to Sourcing database, I want the script to replace the user id typed in by the buyer with the user id provided by the other system

Former Member
0 Kudos

What is the context of your script, are you writing it on validate?

Former Member
0 Kudos

Scripting context is Document Lifecycle Event, Class - Contact(600), Target - Saved

former_member89217
Contributor
0 Kudos

The saved target does not seem to be the proper target. Saved target tries to modify the object after it has been saved which is a generally a bad idea. the saved target would be appropriate to modify something other than the object refernced by "doc".  for instance in an integration senario when something of object type A is created do something to object type B or do something in a different system related to the object just saved.   SInce I would expect this to be a ONE TIME action.  Try the created target. It will only happen once. when the item is created.

Gary

Former Member
0 Kudos

Hi Gary,

I tried the same script on Target Created. But the script is getting called when I click "Add" button to add a contact. I need some information like contact first name, last name, email address etc and pass these to a third party system which generates user id. If I write script on Target Created, then it gets called before user can enter the name and email info in the create contact page. Can you please let me know what is the correct Target for this case?

Former Member
0 Kudos

I tried writing the script on Target Validated and included just the get name method:

currentRec = doc.getObjectReference();

contactHome = (ContactIBeanHomeIfc)IBeanHomeLocator.lookup(session, ContactIBeanHomeIfc.sHOME_NAME);

contact = contactHome.find(currentRec);

message = "Hello my first name is " + contact.getFirstName();

.. print out message

While creating a new contact record and saving, this script got executed and gave a null pointer.. this is the error message I got:

Error executing script: Sourced file: inline evaluation of: ``import com.sap.odp.api.ibean.*; import com.sap.odp.api.ibean.common.*; import . . . '' : null.

Former Member
0 Kudos

Just found out that the null pointer was because the contact object was null.. i am able to get doc.getObjectReference() but not able to use it to look up a contact record.. I guess the contact record is not yet saved that is why it is returning null..

I tried typecasting the doc.getObjectReference() to ContactIBeanHomeIfc and then calling the getFirstName() method that didnt work (again null)..

How can I access the field values using the current object reference?

Former Member
0 Kudos

Found the problem.. I have to call the methods directly on doc. Since validated is called before the record is saved, doc,getObjectReference() will not have the required values.. i have to directly call doc.getFirstName(), doc.getLastName() etc

Answers (0)