Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I've a requirement to find out whether a field is currently locked, in order to display a Lock / Unlock button.
Obviously I can use a variable on a toggle, but this can be foxed by a user locking or unlocking the selection themselves without using the button.
There doesn't seem to be any way using GetCurrentSelections() to discern if a field is locked or not.
Has anyone got a clever way of doing this?
Cheers,
Steve
Not sure what the IsLocked or AlwaysOneSelected flag would do in the context of field settings in the QVD. Perhaps it is a hint to what should happen with that field if it is later created as a list box. If the QVD was created from a load script that would not be possible to set these flags (as far as I know). Perhaps it only kicks in if you export a QVD from the UI, rather than the script?
One only hic could answer, I suspect...
Hi Steve,
In attached document a macro to get the list of locked fields and its documentacion.
Br,
Juan
Since this got necro-bumped, and it's kind of interesting, I figure I may as well ask.. why check the lock state in the first place? There are field event triggers for OnLock and OnUnlock, and they're catch-all (they will trigger when the field is locked by an action, a manual lock, or a "Lock all"). You can use these with whatever action you prefer - minimize/maximize, set variable, or whatever else fits.
It's not technically the same thing as checking the state, but it feels like this achieves the same thing without the need for a macro or long-form workarounds that impact performance.
I'm not sure if this is something that was added semi-recently, but it feels like these triggers have been around for a while.
Hi Shoham,
True if the fields you can track lock status are known, but if not, the evens lock or unlock field can’t set for all fields in the model. This macro operates for any field in the document.
Br,
Juan
Why not?
https://community.qlik.com/docs/DOC-19141
Doesn't take more than minor customization and while it requires a macro, you only have to use it once in developer mode, so this is AJAX-friendly.
The only reason I can think of to stick with a macro solution is if you are dealing with multiple fields being locked and you need to know all of them and actually use those field names in actions. In that case, it might be a cleaner approach than using variables - but even then, I think variables would get the job done. For the use case described above - knowing if a single field is locked - the field event trigger seems very appropriate.
The following is technically also not exactly what you were looking for, but might just cover what the user actually wanted
It will contain a macro though 😉
I was also trying to show an lock/unlock button in dependence of the lock state. Then I realized, that what we actually need is the ability to unlock, when it is locked and to lock when it is unlocked, right? And the field is shown right there next to the button anyway, so the lock state itself is in plain sight.
So I switched one button with a toggle functionality. The macro in the background will check if the field is already locked and unlock it, if it is and lock it, if it isn't. It is rather simple, but here it is anyway
sub ToggleFieldLock(fieldName)
' get the field to work on
set field = ActiveDocument.Fields(fieldName)
' if it is already locked
if(field.GetLocked) then
' we want to unlock it
field.Unlock
else
' otherwise we lock it now
field.Lock
end if
end sub
Sandro