0

I have created a formula field User Timezone and I want the current login user timezone value.

I have written the formula

User Timezone = TEXT($User.TimeZoneSidKey)

but I am getting the value Asia/Kolkata but I want (GMT+05:30) India Standard Time (Asia/Kolkata) this value in my formula field. Please help me to achieve this.

enter image description here

1 Answer 1

1

As far as I know, there is no such formula function to get the picklist label yet. You can do some workaround by apex code.

Create a new text field TimeZone_Txt__c to store the timezone label text. Write some code in trigger to set the label to the text field before any user is created or user timezone is changed. Some code for your reference:

if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate)) {
    Map<String, String> val_labelMap = new Map<String, String>();
    for(Schema.PicklistEntry et : User.TimeZoneSidKey.getDescribe().getPicklistValues()) {
        val_labelMap.put(et.getValue(), et.getLabel());
    }

    for(User u : Trigger.new) {
        if(Trigger.oldMap != null && u.TimeZoneSidKey == Trigger.oldMap.get(u.Id).TimeZoneSidKey) {
            continue;
        }
        u.TimeZone_Txt__c = val_labelMap.get(u.TimeZoneSidKey);
    }
}

Export all the existing user with Id and timezone info(label) by report. Update back to TimeZone_Txt__c field.

Use $User.TimeZone_Txt__c instead.

More reference: PicklistEntry Class

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .