Dynamic Setcurrentkey

Hi All,

Can I assign the setcurrentkey dynamically. I am facing the problem with sorting Order.

I have given some fields on the form so as user can select which type of sorting he wants, as per his selection the system should set the setcurrentkey of the specified table.

Regards,

Naman

Hi Naman,

Welcome to the user group. As a new member you should read the How to ask a new question first.

But in order to help you then we need to know exactly what your problem is and where are experiencing this problem. You should also always remember to mention which product and version you are using.

Hi Erik,

I am using Microsoft Dynamics NAV Version 6.0. I have given a form to the user to select the fields in which he’ll like to sort the data.

To sort the data, I need to make a key wrt the fields selected on the form by the user. I am able to enable the key as per the selection in the form but I not able to put that key in setcurrentkey so as data should be sorted as per that key.

Thanks,

Naman

Hi Naman,

What I think you are trying to create is a “performance killer”! You can easily allow the users to select the key they want to use, but only amoung the existing keys. Allowing the users to create their own keys would require that they all are create as “database owners”, which is not a good idea.

Instead rethink this request and create only the keys which are really required and then let the users select between these keys.

Hi Erik,

I am now allowing the users to create their own keys, the keys are there in the table with Keygroups. As per the selection I am only enabling the keygroup then doing some processing & then again disabling the keygroup through code. For processing the data I want to use the key that has been enabled in setcurrentkey & I am not able to use it. this is the main problem I am facing.

I will try some other method to overcome this problem.

Regards,

Naman

Do you mean to say user will select the fields from table for creation of keys and on that basis the report will be created. ???

Hi Amol,

I am having 4 fields as per which I can have 24 combinations for keys, I have created all the combinations & defined them as keys in the table. Right now all these 24 keys are disabled. As per the selection of fields by user the respective key will be enabled. Now I have all the fields which are in the key as per the order. for e.g. I have four fields “a,b,c & d”. There can be 24 combinations in which the user can select the key. Say user has selected key “abcd”. This key will be available in the table but it will not be enabled. I will enable this key through code. I will be having one text variable which will be holding this key as keyvar := “abcd”.

Now the problem is that how can I use the setcurrentkey function like Table.setcurrentkey(keyvar); as if I am giving this, the system is giving me the error that “A field from record variable was expected.”

Regards,

Naman

Ok, now I understand what you are doing. So you are not actually creating new keys, you just want to programatically allow the users to select their own keys and enable/disable them using key groups?

You cannot do it the above way by just adding a keyvar. I can see two ways to do this.

Either you have to “hardcode” all your 24 keys into a selection and then using a CASE statement (or similar) to set the SETCURRENTKEY.

Or you can use RECORDREF combined with the KEYREF functionality. It’s not beginner stuff to work with KEYREF’s - and if you want to see it in action, then you should check out how Microsoft have developed the Outlook Synchronization functions in NAV. Here they use KEYREF a lot.

Hi Erik & Amol,

Thanks a lot for your valuable advice. I hpoe I can do it with the help of recordref & keyref.

Best Regards,

Naman