Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

macro to replace always one selected option

I need to create a macro that basically replace the option "always one selected" for a multi box or list box. Either when the document is opened or when a sheet is opened, I want a selection or the first selection of a field in a multi box or list box to be selected. This field should not allow the selection to be cleared but should allow the user to make another selection from the field.

For example, if I have an employee name as a field in a multi-box, then when I open the document or switch to that sheet, the macro should force a name to be selected. I should not be able to clear the selection because at least 1 name should be selected. HOwever, he user should be able to select another name from the list.

I have never created a macro so I am not even sure where to begin. Any help would be greatly appreciated!

10 Replies
Not applicable
Author

Hello ,

Attached is the simple example see the document properties _ macros maybe this is the way you are looking for

Talha

Anonymous
Not applicable
Author

Just curious - why not to use "always one" option?

Not applicable
Author

After the document has been reloaded on the server nothing is selected, so "always one" is not checked.

Marko

Not applicable
Author

Hi Marko,

I have seen this "always one selected value" setting removed after reload before. The reason was because the default clear state was set before the "always one selected value" setting was applied. This may be the case in your application too. If it is you will need to apply the setting and set the default clear state again.

Kind Regards

Footsie

Not applicable
Author

I see the issue with this loading as well. We also have other issues pertaining to the always one selected as well.

I have been playing around with the macro information provided in the APIquide.QVW but since I am not at all familiar with this stuff, I am struggling. I was playing with things I saw in there such as SearchToggle and SetInputFieldValue but no luck.

Anonymous
Not applicable
Author

I see...
In this case I use a macro that selects a default value and sets this "always one" option. Stilla mcro, but a very simple one.

Not applicable
Author

That is the macro that I have been trying to create but need some assistance. I was able to figure out that the following macro would select all, a group,or one but only if the specific one you use is in the list which will not always be the case in scenario. I also have not been able to figure out the "always one selected" part of the macro either.

Any assistance with this is much appreciated!



function

{

ActiveDocument.Fields("ResidentName").ToggleSelect("A*")

}

Select()



Anonymous
Not applicable
Author

Here is an example for "always one selected" part of the question. You have to make a selection first for this macro to set this property.


Sub SetOnlyOne
set wk=ActiveDocument.GetField("WeekOf")
wSel=wk.GetSelectedValues.Count
if wSel=1 then
set prop = wk.GetProperties
prop.OneAndOnlyOne = true
wk.SetProperties prop
end if
End Sub


Not applicable
Author

Hi,

Where do you call this macro from?

I am working on the same topic, but need to publish my QV file on a QV server

I was considering to trigger this from the PostReload trigger, but I understood the macro will not run as the reload is performed on the server

Then, OnOpen trigger, but the method 'SetProperties' does not seem to be applied.

set prop = wk.GetProperties

prop.OneAndOnlyOne = true

msgbox prop.OneAndOnlyOne

wk.SetProperties prop

msgbox prop.OneAndOnlyOne

will give me 2 'False' result.

Have you experience the same?

I have the same behavior by placing a button which calls the macro.