I am trying to create a set of tasks when a custom entity reaches a certain stage. I want the task to allocated to the owner of the customer entity and also be associated with the customer entity so other users can track the process of the tasks without knowing who is doing them.
I am retrieving multiple records from another table that store the task I need hence the result.entities[I] (this works)
This is what I have but I get the error message [object Object]
var vGoLiveDate = Xrm.Page.getAttribute("new_golivedate").getValue();
var date = new Date(vGoLiveDate);
var newdate = new Date(date);
var daysbeforgolive = result.entities[i].new_daysbeforegolive
var vStartDate = newdate.setDate(newdate.getDate() - daysbeforgolive);
var today = new Date()
if (vStartDate < today){
vNoTime = "Yes"
}
var sGUID = Xrm.Page.data.entity.getId();
var ID = "/clockworX_OnBoardings(" + sGUID .substring(1,37) + ")";
var lookupObj = Xrm.Page.getAttribute("new_ownerid")
if (lookupObj != null) {
var lookupObjValue = lookupObj.getValue();
if (lookupObjValue != null) {
lookupRecordGuid = lookupObjValue[0].id
var ownerid = lookupRecordGuid.substring(1,37)
}
}
var sSystemUser = "/Users(" + ownerid + ")";
alert(ID);
alert(sSystemUser);
var entityName = "task";
var Data =
{
"subject": result.entities[i].new_name,
"ownerid@odata.bind": sSystemUser,
"actualstart": vStartDate,
"category": "On Boarding",
"description": result.entities[i].new_notes,
"regardingobjectid@odata.bind": ID,
}
Xrm.WebApi.createRecord(entityName, Data).then(
function success(result) {
var accountId = result.id;
alert(accountid)
},
function (error) {
var alertStrings = { confirmButtonLabel: "Yes", text: error };
var alertOptions = { height: 200, width: 350 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
);