Article: AN0002365Updated: 04.11.2018
In this case study we will show how to create a Survey functionality in ObjectGears just in few clicks. The purpose of this case study is not to demonstrate ObjectGears as the best solution for Surveys and Questionnaires but as a general platform on which even user without coding skills can create easily various solutions. We will demonstrate it now on a survey example.
Advantages of the ObjectGears survey towards similar internet services:
- your data will stay in the company
- implementation within couple of minutes
- no need to purchase anything
- you can link it with data already existing in ObjectGears
- you can create reports and monitor how users are responding
Description of requirements
We will use the survey in situations when we need to get answers to several questions from all users or from a certain user group. we will create a class with scripts and send a link to users by an email. This link is the same for all the users which simplifies it. User will click on the link and displays a new record. If the user already created the record, he or she will be redirected to his/her record.
Survey owner can browse all the created records, monitor who responded and who not and correct the date in case of mistakes.
Implementation
We have to create one class, columns according to the questions that we need to answer and one rule to bring the solution alive. That`s several clicks in ObjectGears. You can add an explanatory description and a tooltip that will be displayed for each particular column. That`s in particular language versions in order users can see all the names and descriptions in their language.
One of columns has to be type Reference to a user and below stated scripts assume that its code is assigned_to.
We will set up access rights in the class for the built-in ObjectGears role:All authenticated users - read/create/change.
If you need access just for selected users then you can use a new role and assign users to it. Access will be denied to other users.
We will create a class Rule of type Script: Before record display
We will use below scripts in the class:
Script for list of records
Simply copy-paste below code into the class that you created. Below example works with a role admin. State a code of the role that the survey owner will actually have in your instance.
function OnLoad()
{
if (!OG.Person.IsUserInModelRoleByCode('admin', OGModel.Id)) //State here code of the survey owner role
{
OGForm.RedirectTo(OGClassDef.NewDetailUrl); //User without above role will be redirected to his/her record when accessing list of records.
}
}
Script for record detail
Simply copy-paste below code into the class that you created. Below example works with a role admin. State a code of the role that the survey owner will actually have in your instance.
function OnLoad()
{
OGEditOptions.EnabledCreate = false;
OGEditOptions.EnabledCreateAsNew = false;
OGEditOptions.EnabledDelete = false;
var p = OG.Person.GetLoginPerson();
//in case of a new record check whether a user record exists and if so display this already existing record
if ( OGDataRowId == null)
{
var f = OG.DataRow.GetDataRowFilter(OGClassDef.Id);
f['assigned_to'] = p;
var drl = OG.DataRow.GetDataByFilter(f);
if ( drl.Count > 0)
{
OGForm.RedirectTo(drl[0].DetailUrl);
}
}
else
{
//in case of edit request check that the user tries to edit hi own record or he is an Administrator - State here the role that the Survey owner actually has in your instance
if (!OG.Person.IsUserInModelRoleByCode('admin', OGModel.Id))
{
var dr = OG.DataRow.GetDataById(OGClassDef.Id, OGDataRowId);
if ( dr['assigned_to'].Id != p.Id)
{
//if the user tries to edit a record belonging to somebody else go to his record
OGForm.RedirectTo(OGClassDef.NewDetailUrl);
}
}
}
}