<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged gamification-module</title>
<link>https://overflow.efficy.io/?qa=tag/gamification-module</link>
<description>Powered by Question2Answer</description>
<item>
<title>sharing: serverside module to set json data in db (encapsulate the EfficyAPI calls)</title>
<link>https://overflow.efficy.io/?qa=5062/sharing-serverside-module-json-encapsulate-efficyapi-calls</link>
<description>&lt;p&gt;Hi developpers community, &lt;/p&gt;

&lt;p&gt;this is a serverside module I use to set json data in DB quickly in serverside js that encapsulate all the EfficyAPI calls.&lt;/p&gt;

&lt;p&gt;so basically i want to add a company in db i just have something like this to code : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rec.set({
    k_company: 0,
    name: &quot;ma société&quot;,
    kind: 3,
    memo: &quot;company created by a cool js module&quot;
})
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;this is a more complete example of what you can set&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var inserted = rec.set({
    k_company: 0,
    name: &quot;my company&quot;,
    kind: 3,
    memo: &quot;company created by a cool js module&quot;
});

// inserted == 3001

var arrayInserted = rec.set([
    {
        k_company: inserted,
        memo: &quot;updated memo&quot;
    }, {
        k_company: 0,
        name: &quot;my second company&quot;,
        f_custom_field: &quot;valuecustom&quot;
    }
]);

// arrayInserted == [3001, 3002]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;declaring the module&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;//@import rec from finopsys/recordMgr
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;initializing the module (setting the entity you want to set)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rec.init({
     entity: ntComp
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;note that you can import several instances of this module if you don't want to reinitialize the module on each call (in case of you have serverals record kinds to set for each line)&lt;/p&gt;

&lt;p&gt;you can also add special properties to the record parameter &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var inserted = rec.set({
    k_company: 0,
    name: &quot;my company&quot;,
    kind: 3,
    memo: &quot;company created by a cool js module&quot;,
    s_usersecurity: [{k_user: 1, security: 3}],
    s_detail2: [{entity: ntCont, key: 365}]
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;s&lt;em&gt;usersecurity: [{k&lt;/em&gt;user: 1, security: 3}]&lt;br&gt;
add the security level 3 to the user 1 to this record (setUserSecurity)&lt;/p&gt;

&lt;p&gt;s_detail2: [{entity: ntCont, key: 365}]&lt;br&gt;
add a link to the contact with key 365 (insert detail2)&lt;/p&gt;

&lt;p&gt;this is the code of the module : recordMgr.js&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;//@import $ from finopsys/jUtils

return (function(){
var options = {
entity: ntComp,
keyfield: &quot;k_company&quot;
};

function test(){
return &quot;returned from custom server module&quot;;
}

function init(_options){
if (typeof _options === &quot;object&quot;){
$.forEach(Object.keys(_options), function(_key){
if (options.hasOwnProperty(_key)) options[_key] = _options[_key];
});
}

options.keyfield = Efficy.sqlQueryValue([
&quot;select &quot;,
&quot;    LOWER(F.NAME)&quot;,
&quot;from&quot;,
&quot;    &amp;lt;#TABLE NAME=SYS_FIELDS&amp;gt; F&quot;,
&quot;    inner join &amp;lt;#TABLE NAME=SYS_TABLES&amp;gt; T on T.K_TABLE = F.K_TABLE&quot;,
&quot;    inner join &amp;lt;#TABLE NAME=SYS_ENTITIES&amp;gt; E on E.K_TABLE = T.K_TABLE&quot;,
&quot;where&quot;,
&quot;    F.USAGE = 'K'&quot;,
&quot;    and E.K_ENTITY = :param1&quot;
].join(&quot;\n&quot;), options.entity, &quot;&quot;);

return options;
}

function set(_data){
var result;

if (typeof _data !== &quot;object&quot;) throw new Error(&quot;the records to set are not in an array&quot;);
if (_data.hasOwnProperty(&quot;length&quot;)){
result = setRecords(_data);
} else {
result = setRecord(_data);
}

return result;
}

function setRecord(_record){

if (typeof _record !== &quot;object&quot;) throw new Error(&quot;the record to set is not an object&quot;);
if (!_record.hasOwnProperty(options.keyfield)) throw new Error(&quot;the record to set has no keyfield property&quot;);

var key = _record[options.keyfield];

var editHandle = Efficy.openEditContext(options.entity, _record[options.keyfield], false);
try {
var ds = Efficy.getMasterDataSet(editHandle, 0);
ds.edit();

$.forEach(Object.keys(_record), function(_key){
if (_key === options.keyfield){
key = ds.fieldByName(_key).value;
} else if (ds.findField(_key)) {
if(typeof _record[_key] === &quot;string&quot;) ds.fieldByName(_key).asString = _record[_key];
else ds.fieldByName(_key).value = _record[_key];
}
});

if (_record[&quot;s_usersecurity&quot;]){
$.forEach(_record[&quot;s_usersecurity&quot;], function(_usersecurity){
Efficy.setUserSecurity(editHandle, _usersecurity.k_user, _usersecurity.security);
});
}

if (_record[&quot;s_detail2&quot;]){
$.forEach(_record[&quot;s_detail2&quot;], function(_detail2){
Efficy.insertDetail2(editHandle, _detail2.entity, _detail2.key, false);
});
}

Efficy.commitChanges(editHandle, false);            
} finally {
Efficy.closeContext(editHandle);
}

return key;
}

function setRecords(_records){
var result = new Array();

$.forEach(_records, function(_record){
result.push(setRecord(_record));
});

return result;
}

var public = {
test: test,
init: init,
set: set
};

return public;
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and this is the code of jUtils.js a module I ve done to help the serverside script with some usefull functions &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;return (function(){

function forEach(_array, _iterator){
var result;

for (var i=0; i&amp;lt;_array.length; i++){
result = _iterator.call(this, _array[i], i);
if (result === false) break;
}

return result;
}

function each(_array, _iterator){
var result;

for (var i=0; i&amp;lt;_array.length; i++){
result = _iterator.call(this, i, _array[i]);
if (result === false) break;
}
}

function merge(){
var result = {};

each(arguments, function(_index, _value){
for(key in _value){
if (!result[key]){
result[key] = _value[key];
} else if (typeof result[key] === &quot;object&quot; &amp;amp;&amp;amp; typeof result[key].length === &quot;undefined&quot;) {
result[key] = merge(result[key], _value[key]);
} else {
result[key] = _value[key];
}
}
});

return result;  
}

function getItem(_array, _searchFunction, _startIndex){
_startIndex = _startIndex || 0;

var result = undefined;

forEach(_array, function(_value, _index){
if (_searchFunction(_value, _index)){
result = _value;
return false;
}
});

return result;
}

function format() {
var args = arguments;
var result = args[0].replace(/\$\d+/g, function (cap) {
return args[1 + parseInt(cap.match(/\d+/), 10)];
});
}

function indexOfObject(_array, _searchFunction){

for (var i=0; i&amp;lt;_array.length; i++){
if (_searchFunction(_array[i])) {
return i;
}
}

return -1;
}

function getFunctionName(_function){
var result = _function.toString();
result = result.substr('function '.length);
result = result.substr(0, result.indexOf('('));
return result;
}

var public = {
merge: merge,
forEach: forEach,
each: each,
getItem: getItem,
format: format,
indexOfObject: indexOfObject,
getFunctionName: getFunctionName
};

return public;
})();
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=5062/sharing-serverside-module-json-encapsulate-efficyapi-calls</guid>
<pubDate>Thu, 21 Nov 2019 13:48:55 +0000</pubDate>
</item>
<item>
<title>Gamification Design</title>
<link>https://overflow.efficy.io/?qa=4822/gamification-design</link>
<description>&lt;p&gt;Hello&lt;/p&gt;

&lt;p&gt;Starting to implement the gamification module for a sales promotion starting this week.&lt;br&gt;
I went deeply through  the dev guide but still have some questions that should be share with the Efficy community (&lt;a rel=&quot;nofollow&quot; href=&quot;https://help.efficy.com/edn/dev/crft_11_gam_introduction)&quot;&gt;https://help.efficy.com/edn/dev/crft_11_gam_introduction)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is it possible to change the design of the map ? Does Efficy propose (off the package) other graphics ?&lt;/p&gt;

&lt;p&gt;If within a challenge, a new quizz starts, how can we alert the players ? &lt;br&gt;
Do they have to enter in the game dashboard everyday to check if a new quizz is to be answered.&lt;/p&gt;

&lt;p&gt;Thanks&lt;br&gt;
Patrice&lt;/p&gt;
</description>
<category>How to</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=4822/gamification-design</guid>
<pubDate>Tue, 24 Sep 2019 10:46:43 +0000</pubDate>
</item>
<item>
<title>Implement the &quot;gamification module&quot; in the extranet</title>
<link>https://overflow.efficy.io/?qa=4353/implement-the-gamification-module-in-the-extranet</link>
<description>&lt;p&gt;Hello, &lt;/p&gt;

&lt;p&gt;For one of my customer, we are thinking of using the gamification module, to create quizz / survey in the Extranet. We showed him a few screenshot, he like the idea.&lt;/p&gt;

&lt;p&gt;Would that be hard to implement ? I need to make a first estimate (in hours of dev) before the customer sign for it.&lt;/p&gt;

&lt;p&gt;Regards, &lt;/p&gt;

&lt;p&gt;Loïc&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=4353/implement-the-gamification-module-in-the-extranet</guid>
<pubDate>Fri, 24 May 2019 21:11:20 +0000</pubDate>
</item>
</channel>
</rss>