var msg = //;
var bookableResourceBookings = null;
if (Xrm.Utility.getGlobalContext().client.isOffline()) {
filterQuery = /$filter=msdyn_workorder eq / + workOrderId + / and statecode eq 0 and _bookingstatus_value ne 6eda1f8f-12c2-ea11-a812-000d3a4df1cd/;
}
bookableResourceBookings = await Xrm.WebApi.retrieveMultipleRecords(/bookableresourcebooking/, /?$select=name,bookableresourcebookingid,_bookingstatus_value,_msdyn_workorder_value,_resource_value&$expand=BookingStatus($select=description,name,new_workcomplete)&/ + filterQuery);
if (bookableResourceBookings.entities.length > 0)
{
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var userid = userSettings.userId.replace(/{/, //).replace(/}/, //);
var result = bookableResourceBookings.entities[j];
var workcompleted = result.BookingStatus.new_workcomplete;
{
var bookableresourcebookingid = result[/bookableresourcebookingid/];
var workordername = result[/name/]
if (workordername == undefined)
workordername = new Date().toISOString();
entity[/msdyn_name/] = workordername;
entity[/msdyn_booking@odata.bind/] = //bookableresourcebookings(/+bookableresourcebookingid+/)/;
entity[/msdyn_BookingStatus@odata.bind/] = //bookingstatuses(/+bookingStatusId+/)/;
entity[/ownerid@odata.bind/] = //systemusers(/ + userid + /)/;
entity.msdyn_systemstatus = 690970002;
entity.msdyn_timestampsource = 690970001;
entity.msdyn_timestamptime = new Date().toISOString();
entity.msdyn_generatejournals = false;
await Xrm.WebApi.createRecord(/new_offlinetimeentry/, entity).then(
function success(result) {
var newEntityId = result.id;
Xrm.Utility.alertDialog(/[Async] Success createBookingTimeStamp / + JSON.stringify(newEntityId));
Updaterecord[/bookableresourcebookingid/] =bookableresourcebookingid;
Updaterecord[/BookingStatus@odata.bind/] = //bookingstatuses(6eda1f8f-12c2-ea11-a812-000d3a4df1cd)/; // Lookup
Xrm.Utility.alertDialog(/[Async] BookableResource booking updated / + JSON.stringify(updatedRecordId));
},
function (error) {
Xrm.Utility.alertDialog(JSON.stringify(error));
}
);
}
}
}
},