Change date format based on some criteria Helical Insight 5.0

Hello Team,
I am using Helical Insight 5.0 application. I want to change format of the data based on certain session variable. For example I want to change default format of date yyyy-mm-dd to some other formats based on profile value. How to achieve this in Helical Insight 5.0 ?

Thank you,
Netta.

Hello Netta,

This can be done using Prefetch.

We will think of a scenario like if any user who logs in has profile assigned as date in US format then he will be seeing the data into mm/dd/yyyy format. For some one else having some other user profile value, same report will return the data into let us say dd/mm/yyyy format. So any sort of JS, CSS etc can be changed based on the session variables and this is an example of the same.

In order to achieve the scenario like above, you need to inject below mentioned JS script in PREFETCH while creating a report :

/* Below code is checking the condition if any profile is assigned to loggedin user, if it is not assigned then that user will see data in default format but if US is assigned then data will be in mm/dd/yyyy else for any other profile value it will be in dd/mm/yyyy. Profilename is dateFormat to which profile values are being assigned at user role management level */

manipulateFormData((formData)=>{

if(user.profile[0].profileName==‘dateFormat’){

var profileValue = user.profile[0].profileValue;

if(profileValue == ‘US’){

formData.columns[0].databaseFunction.parameters.format = “”%m/%d/%Y"";

}

else if(profileValue == ‘UK’){

formData.columns[0].databaseFunction.parameters.format = “”%d/%m/%Y"";

}

else{

formData.columns[0].databaseFunction.parameters.format = “”%Y/%m/%d"";

}

}

})

Screenshot1 below show user has profile as US and screenshot2 shows user has profile as UK

image

image

Thank you,
Helical Insight.