cancel
Showing results for 
Search instead for 
Did you mean: 

Maintain drop down list in "Super Commodity"

Former Member
0 Kudos

Hi Experts,

I have new requirement to write the script. in Supplier Info Tab by selecting "Super commodity option, I sould get the related fields in "Sub commodity" drop down list.

For Example : If I select --Travel and Living-- from Super Commoidty, I should get only those value which comes under -


Travel and Living---- in sub commodiry drop down list .

Any help will be apprecited.

Thanks

Iqbal

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Iqbal,

This exact functionality is not possble in SAP Sourcing. Scripts can execute based on certain events only.

I think your best shot would be to write a field data edit script. But tha would also execute on tab changes

Thanks

Devesh

Former Member
0 Kudos

Thanks Devesh for quick response,

Can you please give me some more idea about the script , How to write this or any specific code for this.

Thanks

Iqbal

Former Member
0 Kudos

Hi Iqbal,

The 'Field Data Edit' context allows you to write a script and bind it to a particular field. This script executes on tab changes and, in some cases, automatically (for auto-refreshing fields).

You can write a script on your drop down such that when there are tab changes, your logic is triggered and you are able to set another field based on the new value selected in your drop down.

You should look at the guide for more details.

Thanks

Devesh

Former Member
0 Kudos

Hi,

Thanks Devesh, yes right we can use "Field Data Edit" option in script creation. But I am searching for the appropriate method to set the dropdown with a value list.

I used the following methods:

if(doc.getExtensionField("SUPER_COMMODITY").get().toString().indexOf("Advertising, Promotion and Marketing") != -1) {

doc.getExtensionField("SUB_COMMODITY1").set("vl.sub_commodity_advertising");

}

where "Super_commodity" is name of dropdown 1 based on which dropdown 2(SUB_COMMODITY1) should be populated with new valuelist whose name is "Sub Commodity Advertising" and external id is "vl.sub_commodity_advertising"

I tried running the above script but dropdown2 value isnt changing.

Can you please help me with the right method to be used to do the above operation.

Thanks,

Saloni

Former Member
0 Kudos

Hi Saloni,

Try this :


keyString = "Advertising, Promotion and Marketing";

if(keyString.equals(doc.getExtensionField("SUPER_COMMODITY").get().getDisplayName()))
{
 doc.getExtensionField("SUB_COMMODITY1").get().setDisplayName("Value_needed_in_the_dropdown");
}

If you want to use your resource id to set the value in the drop down then you should first create a ResourceIdIfc object and then pass is to the function setDisplayNameId(resuorceID);

Hope this helps

Thanks

Devesh

Former Member
0 Kudos

Hi,

Thanks again, I am trying what you suggested.

Please can you share your email id.

Thanks,

Saloni, Iqbal

Former Member
0 Kudos

Hi Devesh,

I tried running the code but it didnt work.

I would like to explain the problem again:

In CLM application, for a particular Master Agreement when we select "Supplier Info" tab. There are two drop down on this page.

Super Commodity : ...

Sub Commodity: ...

Right now Sub commodity is showing all values for each type of super commodity. example, if super commodity have {a,b,c} and corresponding to "a" we have {x, y , z } and for "b" we have {p, q, r} and for "C" we have {m, n, o}. Then its showing {x,y,z,p,q,r,m,n,o} in sub commodity.

But we want that when we select "a" in super commodity , we get {x,y,z} only in sub commodity.

We have written "Field Data Edit" script , with below details:

Scripting Context: Field Data Edit

External ID:sap_supplier_info

Application Context: X_Enterprise

Display Name:sup_sub_commodity

Class: Master Agreement(1004)

Instance Type: Any

Document Type: Any

Target: SUB_COMMODITY1

Script:

import com.frictionless.api.doccommon.masterdata.*;

import com.frictionless.api.common.exception.*;

import com.frictionless.api.ibean.IBeanIfc;

import com.frictionless.api.ibean.IBeanHomeIfc;

import com.frictionless.api.contracts;

import com.frictionless.api.usermgmt.masterdata.*;

import com.frictionless.api.common.exception.*;

import com.frictionless.api.common.types.*;

import com.frictionless.api.ibean.*;

import com.frictionless.api.contracts.*;

import com.frictionless.api.doccommon.doc.contract.ContractDocumentIBeanHomeIfc;

import com.frictionless.api.doccommon.doc.contract.ContractDocumentIBeanIfc;

import com.frictionless.api.contracts.*;

import com.frictionless.api.ibean.IBeanHomeIfc;

import com.frictionless.api.ibean.IBeanHomeLocatorIfc;

import com.frictionless.api.common.platform.IapiSessionContextIfc;

import com.frictionless.api.common.platform.IapiDbHandleIfc;

import java.util.*;

import com.frictionless.api.doc.IapiDocumentLockManager;

ApplicationException ae = new ApplicationException(session);

logMsg = Logger.createLogMessage(session);

if (hasValue(doc.getIntCatRef()))

{

intCatHome = IBeanHomeLocator.lookup(session,doc.getIntCatRef());

intCatBean = intCatHome.find(doc.getIntCatRef());

temp = intCatBean.getDocumentDescription();

doc.getExtensionField("INT_CAT_DESC").set(temp);

}

if(doc.getExtensionField("SUPER_COMMODITY").get().toString().indexOf

("Advertising, Promotion and Marketing") != -1) {

doc.getCollnValueListValue("SUB_COMMODITY1").set(null);

}

-


End of Script----


But the above script isnt working. I would like to know what should be "Target" value , Super Commodity or Sub commodity.

Please suggest.

Thanks,

Saloni, Iqbal

Former Member
0 Kudos

Hello Iqbal/Saloni,

Thanks for clarifying your requirements.

Please understand that you cannot choose to show/hide the values of a value list based on some condition. The values can only made Inactive but that removes any reference to that particular value.

AFAIK, what you are looking for cannot be achieved using scripting or configuration.

Up till now I was under the impression that you had to set the the value of a drop down based on the value in another drop down. It was not clear that you wanted a different set of values.

I think the best you can do in this scenario is make all the values visible in the sub-commodity drop down and write a validation script that throws an error if the user selects an invalid combination of super-commodity and sub-commodity.

Also, for field data edit scripts you should use fieldValue and newFieldValue system set variables. I am sorry that I forgot to use these variables in the code snippet in my last post.

Thanks

Devesh

Former Member
0 Kudos

Hi Devesh,

We have already created a validation script and its working fine. But we are also trying other approach to populate the sub_commodity with specific values based on selection in super_commodity. I forgot to mention in my last post that we have created different value lists for different categories of values and named them. example, sub_commodity_adv, sub_commodity_prod, sub_commodity_tech, etc. so I was trying to set those specific value list in sub commodity drop down.

Sample code :

if(doc.getExtensionField("SUPER_COMMODITY").get().toString().indexOf

("Advertising, Promotion and Marketing") != -1) {

doc.getExtensionField("SUB_COMMODITY1").set("sub_commodity_adv");

}

Please suggest.

Thanks,

Saloni,

Iqbal

Former Member
0 Kudos

Hello,

I doubt this is the correct approach.

The value list that an extension field references is mentioned when you create that field. I don't think you can change that reference during run time.

So, even though you have more than one value lists, you can make the same filed reference a different value lists at different times. The only thing that you can change with Value lists is the value that they hold. I hope I am able to get my point across clearly.

Thanks

Devesh

Former Member
0 Kudos

Hi Devesh,

Yes, I got your point. As you have written we cant change value list at runtime , Can you confirm if this can be achieved by writing some procedures or triggers on database end?

Thanks

Former Member
0 Kudos

Hi Iqbal and Saloni,

Sorry I haven't explored that area till now so I don't feel suitable enough to comment.

Thanks

Devesh

Former Member
0 Kudos

Hi Devesh,

Ok no issues. I just got an idea if we can make other items in list inactive/disabled. Do you have any idea, what is the syntax to disable or inactivate values in value list?

Thanks,

Saloni,

Iqbal

Former Member
0 Kudos

Hello,

By syntax do you mean doing it through a script? I wouldn't really recommend doing this with script for obvious reasons. But if you still want to go ahead then here is the approach :

1) Locate the correct Value List Type bean (using external Id)

2) Use the getCollnValueListValue() method on that bean to get a list of all the VLVs in it

3) Iterate over the list and use the setIsIncative() method on the VLV bean that you want to make inactive.

The other way, of course, is to manually navigate to the Value List Types under Master Data, locate you Value List Type, open it and make the required VLV inactive by checking the 'Inactive' check box.

Thanks

Devesh

Former Member
0 Kudos

Hi,

If using script is not the right way then can you suggest some other way out. Validation solution suggested by you before can be cumbersome, as we need to write it for different values in main list corresponding to sub list.

Also, we are facing one more issue. When we tried the below "if condition" in validation script where "Document Lifecycle" context is used , it worked but the same condition isnt working for "Field data edit" context.

example:

if(doc.getExtensionField("SUPER_COMMODITY").get().toString().indexOf("Advertising, Promotion and Marketing") != -1 )

{

doc.getExtensionField("SUB_COMMODITY1").set().toString("None");

}

Any idea? Is there different way to code in Document Life Cycle context and Field data edit.

Thanks,

Saloni,

Iqbal

Former Member
0 Kudos

Hi,

What I meant was that making a value Inactive is NOT the right approach. Making it inactive removes all reference to that value (in terms of APIs). If you make one VLV inactive then it becomes inactive for all the instances of that Value List Type. You cannot make it inactive for one instance and active for another. I hope you are getting my point.

I think writing a validation script for different combinations is the correct and safest approach. I would suggest that you stick to this approach.

To make that script work for Field Data Edit use the newFieldValue system set variable. I have mentioned about it in one of my posts above.

Thanks

Devesh

Former Member
0 Kudos

Hi,

Ok, I got that Inactive isnt possible and validation would be fine. But I wanna try setting the sub commodity drop down to value list corresponding to value selected from super commodity.

Actually our check was not working on "Field Data Edit" at all, so we tried on "Collection validation" script type and the if condition is working now. As here Super commodity and Sub commodity are drop down fields, it may be collection type

i.e.,

if(doc.getExtensionField("SUPER_COMMODITY").get().toString().indexOf("Production") != -1 )

Now, I am trying to set the "SUB_Commodity" to a "production" value list if the above condition is true. But I dont know if any API exists for it.

Can you give any idea how to set valuelist in a drop down options?

I tried below statement but it isnt working...

doc.getExtensionField("SUB_COMMODITY").set("sub_commodity_production");

Please suggest any set api for this.

Thanks