The CreatorCon Call for Content is officially open! Get started here.

I need to show a field message and it should be based on logged user time zone

mania
Tera Contributor

Hi,

 

I have a field called start time of incident that field type is date and time so I need to show a field message and mentioning the time zone in which user has to enter the time and it should be based on logged user time zone.

 

For example:

If I have time zone set in my profile as IST. The message should be "please enter the time in IST time zone".

If I have time zone set in my profile as EST, the message should be "please enter the time in EST time zone".

 

Can you please help on this. It will be useful.

mania_0-1712221156357.png

 

Thanks!

1 ACCEPTED SOLUTION

try this script include. It should work in scoped apps also:

var getUserTimeZone = Class.create();
getUserTimeZone.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUserTimeZone: function() {
        var session = gs.getSession();
        var zoneName = session.getTimeZoneName();
        return zoneName;
    },

    type: 'getUserTimeZone'
});

 

View solution in original post

3 REPLIES 3

kkrushkov
Mega Sage

Hi, @mania 

 

You could achieve this using onLoad Client Script and GlideAjax call: 

 

function onLoad() {

    var userTimeZone = new GlideAjax('getUserTimeZone');
    userTimeZone.addParam('sysparm_name', 'getUserTimeZone');
    userTimeZone.getXMLAnswer(answerParse1);

    function answerParse1(response) {
        var answer = "Please enter the time in " + response + " time zone";
        g_form.showFieldMsg('due_date', answer);

    }
}

 

 

 

Script Include:

 

var getUserTimeZone = Class.create();
getUserTimeZone.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUserTimeZone: function() {
        var myUserObject = gs.getUser();
        return myUserObject.getTZ();
    },

    type: 'getUserTimeZone'
});

 

 

Result:

kkrushkov_0-1712224496961.png

 

 


I hope this information is useful to you! If you have any further questions or need clarification on any point, feel free to ask.

 

Best regards,
kkrushkov

mania
Tera Contributor

@kkrushkov 

 

Thanks for your responding!

 

I have tried which you are provided code but I am getting like the below screen short not taking time zone but my system time zone is US Central.

Can you help me.

 

mania_0-1712224041114.png

mania_2-1712224167582.png

 

Thanks!

try this script include. It should work in scoped apps also:

var getUserTimeZone = Class.create();
getUserTimeZone.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUserTimeZone: function() {
        var session = gs.getSession();
        var zoneName = session.getTimeZoneName();
        return zoneName;
    },

    type: 'getUserTimeZone'
});