web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

Field service mobile app(Resco) - offline js error

(1) ShareShare
ReportReport
Posted on by 144

Hi All,

I am trying to create bookableresourcebooking record using offline js as follows.

function createBooking(ResourceId, ResourceName, workorderId, workorderName, bookingStatusID) {

var startDateTime = new Date();
startDateTime = startDateTime.setMinutes(startDateTime.getMinutes() - 60);
startDateTime = new Date(startDateTime);


var endDateTime = new Date();

var newBooking = new MobileCRM.DynamicEntity.createNew("bookableresourcebooking");
newBooking.properties.starttime = startDateTime;
newBooking.properties.endtime = endDateTime;
newBooking.properties.duration = 1;
newBooking.properties.bookingstatus = new MobileCRM.Reference("bookingstatus", bookingStatusID, "Scheduled");
newBooking.properties.msdyn_workorder = new MobileCRM.Reference("msdyn_workorder", workorderId, workorderName);
newBooking.properties.resource = new MobileCRM.Reference("systemuser", ResourceId, ResourceName);
newBooking.save(function (err) {
if (err != null) {

document.getElementById("error").innerHTML += "<p> " + err + " </p>";
}
else {
document.getElementById("error").innerHTML = "<p> Sucessfully created a booking </p >";
}
}
);
}

But I am geeting following error

Server Error: Length cannot be less than zero. Parameter name: length

I hope this error comes due to start time and end time (when both are equal)

7750.pastedimage1574909237851v1.png

Could please someone help me to resolve this issue?

I have the same question (0)
  • Thomas David Dayman Profile Picture
    11,323 on at

    I think the error might be pointing somewhere else in the code.

    Are you using a parameter called 'length' anywhere?

  • aindike Profile Picture
    144 on at

    Hi Thomas,

    No. In the OOB form also getting this error when strat time and end times are equal.

    Thanks

  • Thomas David Dayman Profile Picture
    11,323 on at

    startDateTime = startDateTime.setMinutes(startDateTime.getMinutes() - 60);

    Maybe its this part of the code?

    Could you try putting static date times in the start and end time?

  • aindike Profile Picture
    144 on at

    Yes. I tried but still no luck.

  • Thomas David Dayman Profile Picture
    11,323 on at

    All I can think of is setting some alerts in your code and see what is being triggered.

    Maybe its the BookableResourceBooking javascript that could be causing the error? Maybe creating a new booking directly in the mobile could cause it to act strange ?

  • britman Profile Picture
    590 on at

    Hi, I am also receiving the same error. I am setting the bookable resource booking start date with current date. Did you find a solution?

  • Community Member Profile Picture
    on at

    could it be due to specifying a required field?

  • Fannie30 Profile Picture
    2,990 Moderator on at

    Questions :1) have you added any logic to the forms via rules? Have you changed the OOB form or OOB logic?  
    2) you said you updated the offline js?  Why?  

    I ask because I am able to create a booking in offline mode with zero issues. 

  • Verified answer
    aindike Profile Picture
    144 on at

    Hi All,

    I have found the error. This error occurs due to the wrong MobileCRM.Reference. I have used the wrong reference.

    newBooking.properties.resource = new MobileCRM.Reference("systemuser", ResourceId, ResourceName); The correct entity is the bookableresorce.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 35 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 27 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 13 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans