Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Now Live: Qlik Sense SaaS Simplified Authoring – Analytics Creation for Everyone: READ DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
guyvermeiren
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
Gysbert_Wassenaar

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
pradosh_thakur
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.
guyvermeiren
Creator
Creator
Author

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

Correct ??

pradosh_thakur
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.
mark6505
Partner - Specialist III
Partner - Specialist III

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

virilo_tejedor
Creator
Creator

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