Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Talk to Experts Tuesday, Live Q&A, September 22: Moving from QlikView to Qlik Sense. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator
Creator

Replacing field in all expressions (Qlik Sense)

Hello,

Is there a way in Qlik Sense to replace all the fields in all expressions in an app by a new field.

The reason is that the fieldname has changed.

Thanks,

Guy

Labels (1)
6 Replies
Highlighted
MVP & Luminary
MVP & Luminary

Yes, you can replace the field by editing all the relevant expressions manually.

Perhaps it's possible to use the QS API. It's at least possible to export the app definition to a json file. You can then edit the json file to replace the field names. See https://github.com/countnazgul/QS-backup-and-restore-app for an example implementation of the json backup-restore mechanism


talk is cheap, supply exceeds demand
Highlighted
Master II
Master II

Never tried this, may be wont work as well

let say your field name was "abc" and now changed to "abc1" . If you create a master item name "abc" may be it will do the trick. Try it and let me know if it works or not.
Learning never stops.
Highlighted
Creator
Creator

What you are suggesting is to re-create the field and give it the former (old) name ??

Correct ??

Highlighted
Master II
Master II

I am asking you to create a master item with the old name. not a field as you need the field to be re-named.
Learning never stops.
Highlighted
Partner
Partner

Hi,

I may be over simplifying , but can you not just alias the new field name to the old one it script?

I.e.

NewField  AS OldFIeld

Mark

Highlighted
Contributor III
Contributor III

It could be great to have such a functionality in the editor.
 
Or even a working script using the API.
 
As a workaround, you can configure and execute the next python script to modify the clipboard.
 
And then perform a 'cut' followed by a 'paste' on every single expression.

The python script is going to do the magic.
 
It will be still a toil, but softer ¯\_(ツ)_/¯
 

 

import win32clipboard
import time

import re

insensitive_count = re.compile(re.escape('count'), re.IGNORECASE)
insensitive_distinct = re.compile(re.escape('distinct'), re.IGNORECASE)
insensitive_field = re.compile(re.escape('FIELD_NAME'), re.IGNORECASE)
def transform_expression(e):
    transform=insensitive_count.sub('SUM', e)
    transform=insensitive_distinct.sub('', transform)
    transform=insensitive_field.sub('NEW_FIELD_NAME', transform)
    return transform

fn=transform_expression
transformed=''
continue_excution=True
while continue_excution:
    try:
        win32clipboard.OpenClipboard()
        clipboard = win32clipboard.GetClipboardData()
        win32clipboard.CloseClipboard()
        
        if clipboard!=transformed:
            transformed=fn(clipboard);
            clipboard=transformed
            print(transformed)
            
            win32clipboard.OpenClipboard()
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardText(transformed)
            win32clipboard.CloseClipboard()
        time.sleep(0.05)
    except KeyboardInterrupt:
        continue_excution=False
    except Exception as e:
        print (e)
        pass