cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a value from ValueList to a select field via Beanshell

Former Member
0 Kudos


Hi

i have to set "no" value to some select fields via Script.

i do something like this:


ValueListTypeIBeanIfc wflValue = findByExternalId("WFL Section Validation");

ValueListValueIBeanIfc wflNoValue = wflValue.getCollnValueListValue().get(1);

logInfo("wflNoValue: " + wflNoValue.toString());

doc.getExtensionField("ZCLM_CRM_HOLD").set(wflNoValue.getLocalizedObjectReference());

after executing this the field is set to "Select...".

the vlvObjRef.toString() show me the correct value: -2147482215:616:No

so i have no clue what i'm doing wrong...

can you help me with this?

thank you

Waldemar

Accepted Solutions (1)

Accepted Solutions (1)

former_member190023
Contributor
0 Kudos

Hello Waldemar,

Please find below a correct code snippet for setting a VLV value:


import com.sap.odp.api.doccommon.masterdata.ValueListValueIBeanHomeIfc;

import com.sap.odp.api.ibean.IBeanHomeLocator;

vlvHome = IBeanHomeLocator.lookup(session, ValueListValueIBeanHomeIfc.sHOME_NAME);

doc.getExtensionField("ZCLM_CRM_HOLD").set(vlvHome.findUniqueByNameType("No", 100603).getObjectReference());

The spec for method: findUniqueByNameType(java.lang.String sValue, int nTypeCode)

sValue - Value List Value Display Name ID

nTypeCode - Value List Type Internal ID


Values provided in code snippet are from my system. Please change to your required values.

Please also note that depending on Script type you may or may not be required to trigger a .save() on the doc.

Regards,

Bogdan

Former Member
0 Kudos

Hello Bogdan,

thank you for your answer.

your code snipplet is unfortunately also not working for me


vlvHome = IBeanHomeLocator.lookup(session, ValueListValueIBeanHomeIfc.sHOME_NAME);

doc.getExtensionField("ZCLM_CRM_HOLD").set(vlvHome.findUniqueByNameType("No", 1039).getObjectReference());


i should set all questions to "no" when the master agreement is duplicated.

so i execute my script on the master agreement lifecycle event "duplicate".

as you can see in the picture below, the fields have after that the value "select.."

when i add the method doc.save() at the end of the script i get an error.

               our value list types definition is as follow:

regards

Waldemar

former_member190023
Contributor
0 Kudos

Hello Waldemar,

That is very strange, because I am using the same script target (Duplicated) and it works fine. For Duplicated script you do not want to save the doc in the script.

Please share your Sourcing system version and patch level and check:

  • Extension Definitions, ensure that field names are correct
  • check value of ZCLM_SRM_HOLD after the vlv set by logging doc.getExtensionField("ZCLM_CRM_HOLD").get().toString()
  • check if value is overridden somewhere else (maybe in a FDE script)

Regards,

Bogdan

former_member190023
Contributor
0 Kudos

There is also another possibility for this behaviour, that is not related to the code itself.

Can you share following info:

  • ESO version and patch level
  • Are there any Field Data Edit scripts defined for MA class?

Bogdan

Former Member
0 Kudos

Hello Bogdan,

you was in right. an other programmer was override the value befor saving the contract.

it works now correctly.

both solutions; mine and yours

i have an another question arroud this theme:

i am trying to do the same on the "Field Data Edit" event of Question1.

e.g. if the Question1 was switched to "yes" then Question2 should change "on the fly" (without saving) the Value to "no".

so i do something like this:


if (newFieldValue.getDisplayName().equals(VAL_YES)) {

  logInfo("ZCLM_WFL_002 value before: " + doc.getExtensionField("ZCLM_WFL_002").get().getDisplayName());

  vlvHome = IBeanHomeLocator.lookup(session, ValueListValueIBeanHomeIfc.sHOME_NAME);

     doc.getExtensionField("ZCLM_WFL_002").set(vlvHome.findUniqueByNameType("No", VALUE_ID).getObjectReference());

  logInfo("ZCLM_WFL_002 value after: " + doc.getExtensionField("ZCLM_WFL_002").get().getDisplayName());

}

when i look in the log files then i can see that the value was changed to "no". but on the screen after the screen was refreshed i can see still the old value in Question2 select field. do i have to do something like save or persist the new field value?

Thanks

Waldemar

former_member190023
Contributor
0 Kudos

Hi Waldemar,

It's good that the setter worked, I was afraid of some other bug CLM has in V9 SP14.

  • both solutions should work correctly, but from a DB perspective, using .get(1) does not guarantee 100% that the 'No' value will be fetched (auto-reindexing of the DB might switch them around).
  • The code I'm using is 100% proof and also a bit more efficient in terms of speed and readability.

For the dependent VLVs, there are a few comments:

  1. no need for persisting (saving) the values (because the user doesn't expect the doc to be saved when changing a VLV, it's counterintuitive)
  2. check if the Question2 value changes after changing tabs (it should):
    • Set Q1 to 'Yes'
    • Change Tab on MA - then change back to original Tab

What happens in CLM is that the FDE script is not actually executed when the Q1 value is set, but when the page is refreshed (tab-change). Some fields (aka Currency) have built-in auto-refresh, but not the extension fields.

This is a big limitation everyone is hitting, and I have seen a promise from SAP that V10SP6 will include a PageCusto that you can set to have 'auto-refresh' on any field you like. Only then you will be able to have 'live' dependent fields.

Bogdan

Former Member
0 Kudos

Hi Bogdan,

thank you for your explanations.

i'm also a big fan of efficiency so i choose as well your code

i'm working with

Application Version: 10.0.06.00 build 253628

Schema Version: 10.0.06

after changing the tab the value in question2 is not changing to the expected value.

I can observe the following sequence of events:

1. when i choose in Question1 the value "yes" the  "Field Data Edit" event is fired.

2. the script is changing the value of Question2 field to "no"

3. i can see it in my log file: value before: "Yes" - value after: "No"

4. after that, the system refresh the page itself.

5. i can see that the value in Question2 on the screen was not changed.

if i do it immediately again (without page refresh/reload myself)  and set the value in Question1 again to "yes" i get exactly the same output in log file: value before: "Yes" - value after: "No"

it seems that some event is setting the value of Question2 back to the original value after i was changing it via Beanshell to "no".

i have no idea what i can do with this...

we need a questionnaire that interact with the user before we save the master agreement.

maby someone had a similar problem

regards

Waldemar

former_member190023
Contributor
0 Kudos

You can put an FDE script on Q2 and log the before and after values (using built-in variables fieldValue and newFieldValue). Or check if you have an existing FDE script on Q2, it could be overwriting your value.

With the log you could see if any script is changing the value of Q2 back.

Bogdan

former_member190023
Contributor
0 Kudos

PS: It looks like you are already in SP6. Could you help with a request? If you add a new PageCustomisation for MA -> on one of the custom VLV fields, can you take a screenshot of the option list in Property column?


Thanks,

Bogdan

Former Member
0 Kudos

you are welcome

Former Member
0 Kudos

Hi Bogdan,

after we talked with SAP, we get the statement that this behaviour ist normally. the self defined fields will not be refreshed after change from script. SAP also not planned to chage this behaviour.

the only way to do what i want is over the validation with rules designer.

regards

waldemar

Answers (1)

Answers (1)

former_member207877
Active Participant
0 Kudos

Hello Waldemar,

Try below code and check

import com.sap.odp.api.doccommon.masterdata.ValueListTypeIBeanHomeIfc;

sMA_YES/NO_VLV = "z_yes_no";


vlvTypeHome = IBeanHomeLocator.lookup(session, ValueListTypeIBeanHomeIfc.sHOME_NAME);

vlvType = vlvTypeHome.findByExternalId(sMA_YES/NO_VLV);

vlvColl = vlvType.getCollnValueListValue();

vlvItr = vlvColl.iterator();

while(vlvItr.hasNext()){

member = vlvItr.next();

  if(member.getDisplayName().equalsIgnoreCase("Yes")){

  memberName= member.getLocalizedObjectReference();

doc.getExtensionField("Z_MA_COMPETITIVE").set(memberName);

  }

}


Inorder to set the fields which are of Value list value types, you have to use the localizedObjectReference for that specfic values and then use in your code.


Regards,

Raj

Former Member
0 Kudos


Hello Raj,

thank you for your answer, but this is exactly what i'm doing.

i get the value on the direct way:

wflValue.getCollnValueListValue().get(1);  

not over a loop.

regards

Waldemar