cancel
Showing results for 
Search instead for 
Did you mean: 

How to set value for Object property from java code (I am getting value in java code and want to set property of one of Object)?

agentry_src
Active Contributor
0 Kudos

[Migrated from the Syclo Resource Center]

AnilRaghuvanshi   04/20/2011 08:59,

  Hi,  I am getting required value in java code from transaction (setproperty(u.getstring("transaction.propertyname"))) and trying to set it from setter method of Object but could not set it.Could you please,tell me how i can set Object's property's value in from java code.Please,reply as soon as possible.  Thanks in advance

Jason Latko   04/20/2011 09:55

Anil,Could you please clarify the context in which you are attempting this?   If I am correct, you are trying to set a POJO Java Object's properties from the Transaction properties sent up from the client?   The standard Product POJOs all have getter and setter methods that should work for you.   The syntax you supplied looks fine as long as u is a user object.   When you say you can't set it, what is going wrong?   Can you please provide some more information like: Transaction you are using and Object you are trying to populate?   Are you getting an error message in the Java?   Posting your java code that isn't working would be helpful also.   Thanks.Jason Latko - Senior Product Developer at Syclo

april april   04/20/2011 10:16

Hi Anil -I'm not sure I  understand your question. Are you trying to so something like this:       // example Workorder object  Workorder wo = new Workorder();  String desc = u.getString("transaction.description");  wo.setDescription(desc);   If this is not what you are looking for, can you post a snippet of java code so we can see exactly what you are trying to do?Dave

"

AnilRaghuvanshi   04/20/2011 10:37

  Hi,public void setProperties(User u)     throws Exception {                    log.info(""(((((((In material docdu.getString(transaction.orderID)""+u.getString(""transaction.orderID""));          setBPErrorPO(u.getString(""transaction.orderID""));     }from this code I am getting value for orderID and i want to populate this value in property of Materail Document Object   through setter of property  BPErrorPO(from Material Object Document) and here thing is like i want to set this vaule at exception level tht y i am setting it in catch block please have a look on follwing code:-          public void createMaterialDocument(String GM_CODE) throws AgentryException {          System.out.println(""$$$$$$$$$$$$$$$$$$$$$$$$Calling BP subclass createMaterialDocument"");          try {               Logger log = new Logger(_mmUser, ""createMaterialDocument"");               MaterialDocument obj = new MaterialDocument();               MaterialDocumentCreateBAPI bapi = new MaterialDocumentCreateBAPI(_mmUser, new GregorianCalendar(), obj, GM_CODE);                              bapi.run(obj);               System.out.println(""$$$$$$$$$$$$$$$$$$$$$$$$Executed bapi.run and about to processResults"");               bapi.processResults();               log.info(""Created Material Document"");               }          catch (Exception e) {               Logger log = new Logger(_user, ""POReciept"");               MaterialDocumentItem mdi = new MaterialDocumentItem();               try {                    mdi.setProperties((User)_user);               } catch (Exception e1) {                    // TODO Auto-generated catch block                    e1.printStackTrace();               }               log.info(""In GMS BP POOjauser.getString(transaction.orderID)""+_user.getString(""transaction.orderID""));               _mmUser.rethrowException(e, true);          }Ples let me knw how i cn set value of property.Thankx   

"

april april   04/20/2011 10:49

Anil - We are still confused by what you are trying to do. Why do you want to create a MaterialDocumentItemin the exception block of creating a MaterialDocument?  Don't you need the header object t be properly created before you create a detail item?Regardless, if that is what you want to do, then you need to define MaterialDocumentItemin.setProperties(User u) that would look something like this:  public void setProperties(User u) {..._orderID = u.getString("transaction.orderID");}  Dave

"

AnilRaghuvanshi   04/20/2011 11:24

  I have defined setProperty(User u) method in MaterialDocumentObject as below:public void setProperties(User u)     throws Exception {                    BPErrorPO =new String(u.getString(""transaction.orderID""));     }  This method gets called from MaterialDocumentItem. But, the value is still not being populated in the field. Will this require some changes to the transaction mapping as well ?  Any help in this regard will be highly appreciated.  Thanks,Anil           

"

Jason Latko   04/20/2011 11:29

Are you sure the transaction.orderid is populated?   Can you reference this data elsewhere in your java, just not where you would like?   Please verify that you are sure this data is being properly set in your Agentry Transaction.   You can use the Agentry Test Environment to debug the Transaction and verify this also.Jason Latko - Senior Product Developer at Syclo 

AnilRaghuvanshi   04/20/2011 11:41

The value is getting set properly as per the information displayed in logs. But when I check in Test environment, the value is shown as blank.   

Jason Latko   04/20/2011 11:51

Please post the section of your java log showing your transaction values being correctly echoed.   Thanks,Jason - Senior Product Developer at Syclo

AnilRaghuvanshi   04/21/2011 05:15

  please,have a look on log as follows:-createMaterialDocument::(((((((In material docdu.getString(transaction.orderID) 47000249441  value is getting populated properly from transaction but still I a not able to set it by using setter method defined in Object POJO class n even i tested it from test envoirment there it is not showing value but showing value in log .  Thankx in advance 

AnilRaghuvanshi   04/21/2011 05:26

  As I have some urgent requirment if some contact number is provided then that wuould be appretiated .ples let m eknow if any number you can provide to solve this probs bcoz i think there I explain prob properly.Please,reply as soon as possible.

april april   04/21/2011 09:09

Anil - For the quickest resolution to your issue, please contact Syclo Customer Support to work with someone on this issue.Dave

Accepted Solutions (0)

Answers (1)

Answers (1)

Marçal_Oliveras
Active Contributor
0 Kudos


Hi,

I have more or less the same requirement than the creator of this old post migrated from the Syclo forums.

I have added a boolean field to my work order object and I want to set it once the java code has called the SAP BAPI successfully.

I can get the field from the transaction like this:

boolean sentToSAP = _user.getBoolean("transaction.workorder.Z_IsSentToSAP");

And I would like to do something similar but setting the field like this:

_user.setBoolean("transaction.workorder.Z_IsSentToSAP",true);

But I´m not able to do it. I can set the value in the transaction itself but it´s not a valid solution since if the device doesn't have connectivity the field will be marked as true even without calling the SAP BAPI...

Any ideas?

Former Member
0 Kudos

Marcal,

The poster was having issue creating the Object to send to SAP, not trying to set a value in the transaction once it posted.

Once a transaction is created on the client the apply step will change object data, the transaction at that time will still be pending on the client. Also, after the transaction is posted to the backend the transaction is discarded. Once the transaction is posted to the backed the only things the transaction to to the Object are:

1) Nothing

2) Replace Key field
3) Replace whole object

4) Delete Object.

So unless you replacing the whole object, you can not set a non key field once the transaction is posted. and if you replace the whole object, you also have to have all the Object and any sub objects would need to be recreated and send at the same time.

Stephen Streeter

jason_latko
Advisor
Advisor
0 Kudos

Marcal,

Steve is correct.  You cannot replace individual properties of an object in java and return these to the Agentry client's corresponding object.  You would need to replace the entire object by returning the work order POJO object back to Agentry via the transaction steplet.  You can't modify the transaction values in java.  Rather, you would set the boolean in the parent work order POJO object that the stephandler instantiates.  If this is a new property, you would need to add it as a public property in the workorder POJO class and add a getter/setter for that property as well.  The steplet would also need to be modified to pass the object back like so by overriding the getReturnData method of the

com.syclo.agentry.Steplet class:

public SAPObject getReturnData() {

     return _Changed_WO_Object;

}

Changed_WO_Object above is the Work Order instance that you modified to update your new Boolean.  This would pass the object back to Agentry.

I wouldn't recommend this approach.  Replacing objects from java back to Agentry is used mainly to replace new key values that SAP generates, or to reload sub-collections that may have changed during a post.

Here is what I would recommend:  Add a new boolean property to your WO object in Agentry called "NeedsUpdate".  Set this to True when you run your transaction.  After posting your data in your Transmit action, Loop over all the WorkOrder objects in the collection using a sub-action with an execute rule on it.  The execute rule checks for WOs that have the "NeedsUpdate" boolean set.  When it finds one, it runs a silent transaction (transaction without a screen or user interaction) against that WO to set your original "SuccessfullyUpdated" Boolean or whatever you want to call it to "True".  Also set "NeedsUpdate" to false in this final transaction so it wont continue to run.  Then you can base other logic or flow on the value of the "SuccessfullyUpdated" Boolean.

Jason Latko - Senior Product Developer at SAP