Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Start date end Date Not Working

Posted on by 267

Hello Team,

I m facing issue in Start date End date Validation below of my code and here le(Less then equal) and ge (grater then equal) not working 

function projectFilterbasedonDate(executionContext) {

if (Xrm.Page.getAttribute('msdyn_project').getValue() != null) {
var formContext = executionContext.getFormContext();
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var date = Xrm.Page.getAttribute('msdyn_date').getValue();
var year = date.getFullYear() + "";
var month = (date.getMonth() + 1) + "";
var day = date.getDate() + "";
var dateOnly = year + "-" + month + "-" + day;
var resource = Xrm.Page.context.getUserName();
var UserId = Xrm.Page.context.getUserId();
var notificationTime = 5000;
var ERRORID = "ERROR";
var project = Xrm.Page.data.entity.attributes.get("msdyn_project").getValue()[0].id;
var projectName = Xrm.Page.data.entity.attributes.get("msdyn_project").getValue()[0].name;

project = project.replace('{', '');
project = project.replace('}', '');

UserId = UserId.replace('{', '');
UserId = UserId.replace('}', '');


Xrm.WebApi.online.retrieveMultipleRecords("bookableresource", "?$select=_userid_value&$filter=_userid_value eq " + UserId + "").then(

function success(result) {

if (result.entities.length > 0) {

var bookableresource = result.entities[0];
var bookableresourceid = bookableresource["bookableresourceid"];

Xrm.WebApi.online.retrieveMultipleRecords("msdyn_projectteam", "?$select=msdyn_start,msdyn_finish,_msdyn_bookableresourceid_value,_msdyn_project_value&$filter=_msdyn_project_value eq " + project + " and _msdyn_bookableresourceid_value eq " + bookableresourceid + " and msdyn_start le " + dateOnly + " and msdyn_finish ge " + dateOnly + "").then(

function success(result) {

if (result.entities.length > 0) {


} else {


Xrm.Page.getAttribute('msdyn_project').setValue(null);
formContext.ui.setFormNotification("Select project as per valid date", "ERROR", ERRORID);

setTimeout(
function() {

formContext.ui.clearFormNotification(ERRORID);

},
notificationTime
);

}
}

);

}


},
function(error) {

Xrm.Utility.alertDialog(error.message);

}
);

}
}

  • Suggested answer
    Matthew Lazowski Profile Picture
    Matthew Lazowski 3,163 on at
    RE: Start date end Date Not Working

    Also you need to use these APIs to work with msdyn_project entity:

    docs.microsoft.com/.../schedule-api-preview

  • Matthew Lazowski Profile Picture
    Matthew Lazowski 3,163 on at
    RE: Start date end Date Not Working

    Hi Ashik, could you explain without code what you want to achieve?

    There are already some validations in date fields on Project in Proj Ops in CE:

    This info may help:

    0. msdyn_taskearlieststart Task Earliest Start (TES) – used as default start date on new tasks

    1. msdyn_scheduledstart Est. Project Start Date (EPSD) – when there are no tasks, it can be set manually to any value that is before or on EPED. When there are tasks: it can be set manually to any value that is before or on EPED, it does not impact tasks nor is impacted by them.

    2. msdyn_finish Est. Project End Date (EPED)  - when there are no project tasks: can be set manually  to any value that is after or on EPSD. When there are tasks: gets calculated automatically based on end date of latest task and is non-editable.

    3. msdyn_duration Duration (Days) - when there are no tasks, gets recalculated automatically when EPDS or EPED get changed manually. When there are tasks: gets calculated automatically based on start date of earliest task and end date of latest task

    In case a project template is used to create the project, the value we set in msdyn_finish (Est. Project End Date (EPED) will be overwritten on based automatic calculations that take into account Task Earliest Start (TES), start date of earliest task and end date of latest task.

    Kind regards

    Matthew

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans