News & Activity Feed

Tuesday, February 20, 2018 12:33 AM | Claudiu Farcas
Hi community,

Like most of you, we have struggle on making app working across different time zones as we think it is not properly treated by default in COT framework.
Following we will share our solution (best so far in our opinion).

First we make couple of assumptions:
- the SQL server and web server are hosted into an environment with GMT+0 timezone. In our specific case we host the solution in azure.
- we always hold datetimes info in database as GMT+0 in datetime fields (not datetimeoffset - as it does not solve our issue)
- Data clients are responsible to format the data in their own timezones:
a - website will capture datetime offset via some javascript code to set a cookie that will be then interpreted by the ASPNET server side to render propely the webpages.
b - mobile clients that uses REST services should locally handle the datetime values based on their own local timezone.

Steps to implement the solution:
1 - add custom SharedBusinessRules that includes code for injecting JS code (see below).
2 - add custom ApplicationServices to handle user logout to clear previous set cookies (see below).
3 - in COT designer in the controller add two business rules with exact these Id's:
a - AddGmtOffset - command name: Select, type: Code, phase: Execute
b - RemoveGmtOffset - command name: Update, type: Code, phase: Execute
4 - add "GMT" tag your datetime field in the grid as well in the edit/create form. Don't forget about all forms where you use the field.
4 - generate the website.
5 - in VisualStudio editor comment the code that has been generated for the created business rules because will be use those created by us in customized SharedBusinessRules.
6 - rebuild and re-run your project, now those fields should be handled properly in your webpage.

Please have a look on the attached screenshots and match your controllers.

- creation of the business rules (keep exact Id name)

- tag datetime fields in grid view

- don't forget to tag datetime fields in edit/create views

- comment generated code


Custom Code:
- SharedBusinessRules.cs



using System;
using System.Linq.Expressions;
using System.Reflection;
namespace MyProject.Rules
{
public partial class SharedBusinessRules
{

#region GMT OFFSET FIELDS HANDLING

public const string GMT_OFFSET_TAG = "GMT";
public const string GMT_OFFSET_COOKIE = "gmtOffset";

[ControllerAction("", "", "Select", ActionPhase.Before)]
protected void InjectJavascriptGmtOffset()
{
if (Context.Request.Cookies[GMT_OFFSET_COOKIE] == null && this.ControllerName.ToUpper()!="SITECONTENT")
{
string strJS =
//"console.log('GMT OFFSET START');" +
"var d = new Date(); var exhours=1;" // 1 hour expiration
+ "d.setTime(d.getTime() + (exhours * 60 * 60 * 1000));"
//+ "d.setTime(d.getTime() + (exhours * 60 * 1000));" //for testing with 1 min expiration
+ "var expires = 'expires=' + d.toUTCString(); "
+ "Session_gmt_offset = new Date().getTimezoneOffset();"
+ "document.cookie = '" + GMT_OFFSET_COOKIE + "=' + Session_gmt_offset + ';' + expires + ';path=/';"
//+ "console.log('GMT OFFSET ' + Session_gmt_offset);"
;
Result.ExecuteOnClient(strJS);
if (this.View == "grid1")
{
Result.Refresh(true);
}
else if (this.View == "editForm1")
{
Result.HideModal();
Result.ShowModal(this.ControllerName, this.View, "", "");
}
else
{
Result.RefreshChildren();
}
}
}

/// <summary>
/// Adjust DateTime field to include GMT offset
/// used as a Select - Code/Execute Rule
/// rename the rule to "AddGmtOffset" and comment the generated code as this one will be used
/// </summary>
[Rule("AddGmtOffset")]
public void AdjustGmtOffsetImplementation()
{
// This is the placeholder for method implementation.
if (Context.Request.Cookies[GMT_OFFSET_COOKIE] != null)
{
int gmtOffset = 0;
if (int.TryParse(Context.Request.Cookies[GMT_OFFSET_COOKIE].Value, out gmtOffset))
{
foreach (DataField df in this.Page.Fields)
{
if (df.Type.StartsWith("Date") && df.Tag.Contains(GMT_OFFSET_TAG))
{
var orgDateTime = (DateTime?)this.SelectFieldValue(df.Name);
if (orgDateTime.HasValue)
{
var newDT = new DateTimeOffset(orgDateTime.Value, new TimeSpan(0, gmtOffset, 0)).UtcDateTime;
//instance.GetType().GetProperty(df.Name).SetValue(instance, newDT);
this.UpdateFieldValue(df.Name, newDT);
}
}
}
}
}
}

/// <summary>
/// Adjust DateTime field to subtract GMT offset
/// used as a Update - Code/Execute Rule
/// rename the rule to "RemoveGmtOffset" and comment the generated code as this one will be used
/// </summary>
[Rule("RemoveGmtOffset")]
public void AdjustGmtOffsetOnBeforeUpdateImplementation()
{
if (Context.Request.Cookies[GMT_OFFSET_COOKIE] != null)
{
int gmtOffset = 0;
if (int.TryParse(Context.Request.Cookies[GMT_OFFSET_COOKIE].Value, out gmtOffset))
{
foreach (var xpDF in this.NodeSet().SelectView(this.View).SelectDataFields().Nodes)
{
string fieldName = xpDF.GetAttribute("fieldName", String.Empty);
string tag = xpDF.GetAttribute("tag", String.Empty);
if (tag.ToUpper().Contains(GMT_OFFSET_TAG))
{
var orgDateTime = (DateTime?)this.SelectFieldValue(fieldName);
if (orgDateTime.HasValue)
{
var newDT = new DateTimeOffset(orgDateTime.Value, new TimeSpan(0, -gmtOffset, 0)).UtcDateTime;
this.UpdateFieldValue(fieldName, newDT);
}
}
}
}
}
}

#endregion GMT OFFSET FIELDS HANDLING

}
}



- ApplicationServices.cs



using MyProject.Rules;
using System;
using System.Web;
using System.Web.Configuration;
namespace MyProject.Services
{
public partial class ApplicationServices
{
public override void UserLogout()
{
base.UserLogout();
//clean user cookies
HttpCookie cookie = new HttpCookie(SharedBusinessRules.GMT_OFFSET_COOKIE);
cookie.Value = "0";
cookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Set(cookie);
}
}
}



Any comments and improvements are welcome.

Best regards,
Claudiu
Monday, February 19, 2018 10:40 PM | Peter F. Marchal
I make a webclient written in Javascript, HTML5, CSS3 that does calls to the REST appservices. The first time I do a call to the appservices a login page pops up. Therefore I want to program the login in the HTML page.

Is there a way in javascript to automaticly do a login to the application and use REST appservices without having to login manually ?

I use an integrated .net membership in the database.
I do not want to use anonymous REST calls for security reasons.
Monday, February 19, 2018 8:30 PM | Dustin Edgeman
I am on the standard tier S1 for my app. I also have a lot of custom reports that generate .xlsx and .pdf reports for my app. None of my reports work. I am able to download .csv files but nothing else. Please help. I just get errors stating file extension is not valid or is corrupt.
Monday, February 19, 2018 12:22 PM | Christoff Gouws
Why does it happen (regularly) that a user's login doesn't work and you have to retry (with exactly the same credentials), which then works 100%?
Thanks
Monday, February 19, 2018 8:14 AM | Atomic Simply
Hey there
Is it possible to disable the navigaton just on one single page?
On the toher pages the navigation should be normal.
thx for your help
Monday, February 19, 2018 7:54 AM | shyam dharaskar
Is there any way through which I can allow the access of a form to certain number of users based on Organisation Active Directory. If not, please suggest any way to restrict the access of form for certain users?
Thanks in advance.
Monday, February 19, 2018 6:55 AM | Ruby
I have created html page editCustomer and opening in below format:

EditCustomer?_controller=Customers&_command=Select&_argument=editForm2&CustomerId=6738

but this is not working. I have check no exception is occurred in code. if i changed _command=Edit then it's working fine.

can anyone help me why _command=Select is not working?

same i have done for Orders and their it's working fine. below is orders URL which is working correct.

Order?_controller=Orders&_command=Select&_argument=editForm1&OrderId=112
Sunday, February 18, 2018 9:01 AM | amdawi
Hello,
There is an error when open project to design as attached image.
Out of memory

Regards,

Saturday, February 17, 2018 10:53 PM | AlphaBase
Regardless of which app or which model, every time I click on the data tab, the model data doesn't display and I get the error message shown in the image.

I'm using the MySQL connector. Is this a back-end related problem or am I missing a step? The apps all work correctly in the browser.

Friday, February 16, 2018 11:57 PM | Edd
Is there a way to change the Placeholder value using Business rules with a value derived from an SQL expression, example I want to put in a $50 or more on a spending limit depending upon the person.
Friday, February 16, 2018 8:17 PM | shyam dharaskar
Is there any way through which I can allow the access of a form to certain number of users based on Organisation Active Directory. If not, please suggest any way to restrict the access of form for certain users?
Thanks in advance.
Friday, February 16, 2018 4:29 PM | Samuel Ribeiro de Campos
Hi,
is anyone interested to share Five User Unlimited COT License ?
Friday, February 16, 2018 3:19 PM | RREYES3
I am unable to get COT to auto-generate controllers/pages for tables that I have deleted and recreated in the database. I had manually deleted the corresponding controllers and pages before refreshing in COT. The tables does appear in the model designer but no controller or pages are generated.

If I try to manually add controller, fields and pages, I do not get the foreign key fields in the controllers.

It used to auto-generate everything (and we complained), now it seems like it no longer wants to generate from tables it thinks are already in the application.

Is there a setting or way to make it generate everything (fields, controllers, pages,view, etc) for a "table" again?

Thanks

R
Friday, February 16, 2018 3:18 PM | John Willems
I would like to change the code below from a Controller based rule to a SharedBusinessRule. Before I seriously break something I wondered what I needed to change.

Here is a small sample rule I would like to change. The goal is to get ride of my Controller Rule Handlers and just use the sharedbusinessrule class.

I will assume others have done this.

Thanks
=============================================
Namespace AGED.Rules

Partial Public Class LiquorMasterRules
Inherits AGED.Data.BusinessRules

'''
''' This method will execute in any view for an action
''' with a command name that matches "Report" and argument that matches "_blank".
'''

Public Sub r100Implementation(ByVal instance As LiqMastModel)
' Redirect user to another URL
Result.NavigateUrl = String.Format("http://jkwrpc-001-site11.btempurl.com...")
'This is the placeholder for method implementation.
End Sub
End Class
End Namespace
Friday, February 16, 2018 12:40 PM | finbar murphy
HI

While trying to figure out why my cc's on email are not working I found the following
bug/feature

Line 3650 of Business Rules.cs

string bcc = GetActionParameterByName("Bcc");
if (!(String.IsNullOrEmpty(cc)))
AddMailAddresses(message.Bcc, bcc);

I think you want if (!(String.IsNullOrEmpty(bcc)))

This is in Version 8.6.8

Regards

Finbar
Friday, February 16, 2018 6:22 AM | shyam dharaskar
I created two tables:
Countries and State Table.

In state table, I have two columns- State Name and Country.
Now, the reuirement is to load the state dropdown with the selected country in country drpodown.
Can anyone please let me know the steps how to bind the same.

Thanks in advance.
Friday, February 16, 2018 6:20 AM | shyam dharaskar
I created two tables:
Countries and State Table.

In state table, I have two columns- State Name and Country.
Now, the reuirement is to load the state dropdown with the selected country in country drpodown.
Can anyone please let me know the steps how to bind the same.

Thanks in advance.
Thursday, February 15, 2018 5:43 PM | Thomas
Hello COT support-team,
i have a page where the tab key field order is incorrect.

s. video: https://www.screencast.com/t/cCAjQtO0

The fields order is:
Bezeichnung
Nummer
Nummer Teil2
Nummer Teil1und2 (read only calculated field)
überwachungsbedürftig
Artikelart
Mwst
Aktiv

when i tab through the fields the order is
Bezeichnung
Nummer
Nummer Teil2
Aktiv
überwachungsbedürftig
Artikelart
Mwst

why does this happens?

Regards
Thomas
Thursday, February 15, 2018 2:40 PM | John Willems
When I am creating the code to use the global logging do I put it into a business for the specific controller or somewhere else like a new file? If its a new file is there a naming convention to be used?
Thursday, February 15, 2018 12:32 PM | Ruby
I am upgrading my Code on time from 6.0.0.25 to 8.6.11.0 Touch UI.
I have created sample project using code on time tool. In Controller folder generator creates two files for one table, tableName.xml and tabelName.model.xml.
can anyone please explain what is the use of tabelName.model.xml ?
See All Posts