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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

on create of lead record if end date is larger than start date it should restrict the page to save nd create record in crm 365

(0) ShareShare
ReportReport
Posted on by 2,667

Hi all,

while creation of lead record restricting page save & throwing alert pop up but its displaying 2 times means always clicking ok 2 times validation checking end date should not be lesser than start date.

if anyone idea how can pop up only one time.

Thanks,

Jharana

I have the same question (0)
  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at
    RE: on create of lead record if end date is larger than start date it should restrict the page to save nd create record in crm 365

    Hi Jharana Baliyar Singh,

    It is needed to know how you are validating. The easiest way in my mind is to use real-time workflow with a condition and stop workflow (with Cancelled) steps

    pastedimage1672372246227v1.png

    pastedimage1672372324029v2.png

    pastedimage1672372372514v3.png

    Do not forget the trigger

    pastedimage1672372482922v2.png

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: on create of lead record if end date is larger than start date it should restrict the page to save nd create record in crm 365

    Hi,

    Please share your javascript code.

  • Jharana Baliyar Singh Profile Picture
    2,667 on at
    RE: on create of lead record if end date is larger than start date it should restrict the page to save nd create record in crm 365

    Hi Bipin,

    Below code using  & on save event calling :

    /// This Function is used to restrict NRI end time less than start time

    Deal_Retail.RestrictNRIEndTime = function (executionContext) {

       "use strict";

       try {

           var isAlertDisplayed= isAlertDisplayed ? true : false;      

           var formContext = executionContext.getFormContext();

           var lineofbusiness = common_Retail.getAttributeValue(attributes.LINE_OF_BUSINESS);

           if (lineofbusiness !== null && lineofbusiness !== undefined) {

           var lineOfBusinessVal = common_Retail.getAttribute(attributes.LINE_OF_BUSINESS).getValue()[0].name;

           if (lineOfBusinessVal === LOB.MORTAGAGE) {          

           var starttime = common_Retail.getAttributeValue(attributes.CUSTOMERSTARTTIME);

           var endtime = common_Retail.getAttributeValue(attributes.CUSTOMERENDTIME);

           if (starttime !== null && endtime !== null) {

               if (endtime <= starttime) {

                   if (endtime.getTime() <= starttime.getTime()) {

                       //common_Retail.openAlertDialog("Ok", "End Time should be greater than Start time");

                        var message1 = new RegExp(common_Retail.getResourceString(resx.PROSPECT_RETAIL_FORM, "AlertNRIEndTime")).toString();

                       common_Retail.openAlertDialog("Ok", message1.substr(1, message1.length - 2));

                       //common_Retail.setAttributeValue(attributes.CUSTOMERENDTIME);//nulll

                       var eventArgs = executionContext.getEventArgs();

                       eventArgs.preventDefault();                    

                       return;

                   }

               }          

           }

           if(!isAlertDisplayed){

           if (endtime === null || endtime === undefined) {

               isAlertDisplayed = true;

               common_Retail.openAlertDialog("Ok", "End Time should be Entered");

               var eventArgs = executionContext.getEventArgs();

               eventArgs.preventDefault();

               return;

           }

           }

          }

         }

       } catch (e) {

           common_Retail.openAlertDialog("Ok", e.message);

       }

    };

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: on create of lead record if end date is larger than start date it should restrict the page to save nd create record in crm 365

    Hi,

    Which message is displayed twice?

    1. End time should be greater than start time

    2. End time should be entered

    I hope you have not added on change event on start date and end date field.

  • Jharana Baliyar Singh Profile Picture
    2,667 on at
    RE: on create of lead record if end date is larger than start date it should restrict the page to save nd create record in crm 365

    Hi Bipin,

    Thanks for ur response.Yes on save only calling the above method while creating lead End time should be entered showing 2 times. even though am using below script too getting 2 times pop up displaying.

    Here End time field is hidden & both start time & end time showing as pcf control.

    If am setting end time null if its not greater than start time  is it possible to  make this end time field as mandatory as its hidden field & in below screen u can find it added as a pcf control both start & end time field.

    pastedimage1672754405247v1.png
    pastedimage1672754432592v2.png

    /// This Function is used to restrict NRI end time less than start time

    Deal_Retail.RestrictNRIEndTime = function (executionContext) {

       "use strict";

       try {            

           var formContext = executionContext.getFormContext();

           var lineofbusiness = common_Retail.getAttributeValue(attributes.LINE_OF_BUSINESS);

           if (lineofbusiness !== null && lineofbusiness !== undefined) {

           var lineOfBusinessVal = common_Retail.getAttribute(attributes.LINE_OF_BUSINESS).getValue()[0].name;

           if (lineOfBusinessVal === LOB.MORTAGAGE) {          

           var starttime = common_Retail.getAttributeValue(attributes.CUSTOMERSTARTTIME);

           var endtime = common_Retail.getAttributeValue(attributes.CUSTOMERENDTIME);

           if (starttime !== null && endtime !== null) {

               if (endtime <= starttime) {

                   if (endtime.getTime() <= starttime.getTime()) {                  

                       var message1 = new RegExp(common_Retail.getResourceString(resx.PROSPECT_RETAIL_FORM, "AlertNRIEndTime")).toString();

                       common_Retail.openAlertDialog("Ok", message1.substr(1, message1.length - 2));                    

                       var eventArgs = executionContext.getEventArgs();

                       eventArgs.preventDefault();                    

                       return;

                   }

               }          

           }      

          }

         }

       } catch (e) {

           common_Retail.openAlertDialog("Ok", e.message);

       }

    };

    Thanks,

    Jharana

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    RE: on create of lead record if end date is larger than start date it should restrict the page to save nd create record in crm 365

    Hello Jharana Baliyar Singh,

    I have also worked on the similar solution, it was not complicated but have to make sure to format given date field like below. I have only used date only field and it was time zone independent.

    end =  (formContext.getAttribute("ben_enddate").getValue()).format('yyyy-MM-dd');

    after formatting the date field you can compare the results as per different test cases.

    Thank you,

    Amit Katariya

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 117 Super User 2025 Season 2

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 115

#3
Erin Lubben Profile Picture

Erin Lubben 66

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans