-
-
Save chrismauck/0ddb078de3634392e36e to your computer and use it in GitHub Desktop.
Tracking time on slide with Veeva Clickstream object using JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//First thing: get the product SFID | |
function prod_callback(result) { | |
prod_id_array.push(result); | |
} | |
com.veeva.clm.getDataForCurrentObject("KeyMessage", "Product_vod__c", prod_callback); | |
function track(arr) { | |
var prod_id; | |
var obj = { | |
"Track_Element_Id_vod__c": "undefined", | |
"Track_Element_Description_vod__c": "undefined", | |
"Usage_Duration_vod__c": 0, | |
"Answer_vod__c": "", | |
"Usage_Start_Time_vod__c": new Date() | |
}; | |
if (prod_id_array.length > 0) { | |
if (prod_id_array[0].success === true) { | |
obj["Product_vod__c"] = prod_id_array[0].KeyMessage.Product_vod__c; | |
} | |
} | |
function init_callback(result) { | |
data.push(result); | |
} | |
//init_callback(page); | |
com.veeva.clm.createRecord("Call_Clickstream_vod__c", obj, init_callback); | |
var pages = data.length; | |
//console.log(pages); | |
var save = function() { | |
var num = 0; | |
return setInterval(function() { | |
num++; | |
//this.tracking_object[name].time = num; | |
obj["Track_Element_Id_vod__c"] = arr[0]; | |
obj["Answer_vod__c"] = arr[0]; //so reps can see their page history on call reports | |
obj["Track_Element_Description_vod__c"] = arr[1]; | |
obj["Usage_Duration_vod__c"] = num; | |
function callback(result) { | |
update_result[0] = result; | |
} | |
com.veeva.clm.updateRecord("Call_Clickstream_vod__c", data[pages].Call_Clickstream_vod__c.ID, obj, callback); | |
//callback(JSON.stringify(obj)); | |
}, 1000); | |
}; | |
if (interval.length > 0) { | |
clearInterval(interval[0]); | |
} | |
//wait for the create object to return | |
setTimeout(function() { | |
interval[0] = save(); | |
}, 200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment