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 :
Microsoft Dynamics CRM (Archived)

can some body correct me with bellow things please

(0) ShareShare
ReportReport
Posted on by 202

Hi every one 

bellow code written in Java scripts

function getLocation()
{
debugger;
var isCrmForMobile = (Xrm.Page.context.client.getClient() == "Mobile")
if (isCrmForMobile)
{
if (navigator.geolocation) {

navigator.geolocation.getCurrentPosition(showPosition);
} else {
var today = new Date();
today.setDate(today.getDate());
Xrm.Page.getAttribute("actualstart").setValue(today);

}
}
else
{
if (navigator.geolocation) {

navigator.geolocation.getCurrentPosition(showPosition);
} else {
var today = new Date();
today.setDate(today.getDate());
Xrm.Page.getAttribute("actualstart").setValue(today);

}
}
}

//Set Latitude and Longitude field based on GPS co-ordinates.
function showPosition(position)
{
debugger;

var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
Xrm.Page.getAttribute("pcl_latitude").setValue(latitude.toString());
Xrm.Page.getAttribute("pcl_longitude").setValue(longitude.toString());
var today = new Date();
today.setDate(today.getDate());
Xrm.Page.getAttribute("actualstart").setValue(today);

geoTaggingRefresh();
}

we have appointment entity, In that we have Start appointment Button in this entity.

Start appointment Button from ribbon workbench function ==> getlocation(start appointment button commond function)

when we click on start appointment button ....it store the value for latitude and longitude field value.

but what is happening sometimes that ... latitude and longitude field value is not taking , may be because of if users not clicking on start appointment button orrrrrr  may be its not taking value for latitude and longitude because of location tracing problem.

so we are not able to get their location of appointment..

 

please some suggest me urgent what best can be done for this ..

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Amity ,

    Are you getting any error ? I would suggest please try to debug why its not getting where its exactly failing , we are here to help you but you need to be specific which part of code is failing.

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at

    Hi,

    I think there is no issue with the code.

    As it is targeted on mobile clients I think below must be possible scenarios,

    1. Privacy settings - users must enable location setting to track the location.

    2. GPS Location must be enabled in the user mobile.

    3. User must be creating in offline and then it must syncing when he/she comes online 

  • amity Profile Picture
    202 on at

    Hello Das,

    No not any error ...but atleast i want to add value in actual start field so that it will take latitude and longitude value because on click on start appointment button only it take the latitude and longitude value...............

    or  i can stop for mark complete appointment , untill actual start contain value.....

    if this is so then can use this bellow code .....

    function SetActualEndTime()

    {

    var today = new Date();

    today.setDate(today.getDate());

    var actStartDate = Xrm.Page.getAttribute("actualstart").getValue();

    var actEndDate = Xrm.Page.getAttribute("actualend").getValue();

    if(actStartDate ==null)

    {

    alert("Actual start value must be entered before Mark Complete");

    }

    else

    {

    Xrm.Page.getAttribute("actualend").setValue(today);

    }

    }

    but after giving this also if i click ok then appointment will get save and completed...... i want that if actual start field is blank then it should give alert and also it stop to save appointment. ......               again they will click on start appointment so latitude and longitude value will filled up........

  • amity Profile Picture
    202 on at

    Hello,

    Sreevalli Balleda

    This is heppening only in some of the cases ....Actual start field will be blank..

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Okay , just comment out below highlighted line -

    function SetActualEndTime() {
        var today = new Date();
        //today.setDate(today.getDate());
        var actStartDate = Xrm.Page.getAttribute("actualstart").getValue();
        var actEndDate = Xrm.Page.getAttribute("actualend").getValue();
        if (actStartDate == null) {
            alert("Actual start value must be entered before Mark Complete");
        }
    
        else {
            Xrm.Page.getAttribute("actualend").setValue(today);
        }
    }


  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at

    Hi Amity,

    Can you please provide the sequence of actions which you are performing?

    If this location info or Actual Start is mandatory then you should enforce the start appointment button click at some point(Step), so that, users will click the Start button to book the appointment before moving further.

  • amity Profile Picture
    202 on at

    i tried but still same thing ........getting save appointment

  • amity Profile Picture
    202 on at

    Hello Sreevalli,

    thanks for response.

    here is my appointment form 

    after-save-look-like-this.JPG

    firstly user enter all field information after user save the appointment.

    after saving appointment as record 

    when they do appointment then Open records.. screen below..

    after-save-look-like-this.JPG

    then User click on Start appointment button where it store the Actual start(Current Date & time) and also Latitude and longitude value(user Current location)  then after User click on Mark complete button where it store the Actual End (Current Date & time)

    then same time appointment get completed the time user click on mark complete button.

    here is the source code used for this Activity.

    //********************************************************************
    //Get GPS Co-ordinates of the location

    function getLocation()
    {
    debugger;
    var isCrmForMobile = (Xrm.Page.context.client.getClient() == "Mobile")
    if (isCrmForMobile)
    {
    if (navigator.geolocation) {

    navigator.geolocation.getCurrentPosition(showPosition);
    } else {
    var today = new Date();
    today.setDate(today.getDate());
    Xrm.Page.getAttribute("actualstart").setValue(today);

    }
    }
    else
    {
    if (navigator.geolocation)

    {
    navigator.geolocation.getCurrentPosition(showPosition);

    }

    else

    {
    var today = new Date();
    today.setDate(today.getDate());
    Xrm.Page.getAttribute("actualstart").setValue(today);

    }
    }
    }

    //Set Latitude and Longitude field based on GPS co-ordinates.
    function showPosition(position)
    {
    debugger;

    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;

    Xrm.Page.getAttribute("pcl_latitude").setValue(latitude.toString());
    Xrm.Page.getAttribute("pcl_longitude").setValue(longitude.toString());
    var today = new Date();
    today.setDate(today.getDate());
    if(Xrm.Page.getAttribute("actualstart")!=null || Xrm.Page.getAttribute("actualstart")!=undefined)
    {
    Xrm.Page.getAttribute("actualstart").setValue(today);
    }

    geoTaggingRefresh();
    }

    //Set "Actual End Time" field
    function SetActualEndTime()
    {
    var today = new Date();
    //today.setDate(today.getDate());
    var actStartDate = Xrm.Page.getAttribute("actualstart").getValue();
    var actEndDate = Xrm.Page.getAttribute("actualend").getValue();
    if(actStartDate ==null)
    {
    alert("Actual start value must be entered before Mark Complete");
    return false;
    }
    else
    {
    Xrm.Page.getAttribute("actualend").setValue(today);
    }
    }

    //Refresh Map section on save.
    function geoTaggingRefresh()
    {
    debugger;
    var latitude=Xrm.Page.getAttribute("pcl_latitude").getValue();
    var longitude=Xrm.Page.getAttribute("pcl_longitude").getValue();
    if(latitude != null && latitude != undefined && longitude != null && longitude != undefined)
    {
    var wrControl = Xrm.Page.ui.controls.get("WebResource_Map");
    //wrControl.setSrc(wrControl.getSrc());
    var wrControlName = wrControl.getSrc();
    wrControl.setSrc(null);
    //Xrm.Page.ui.tabs.get("appointment_section_7").setVisible(true);
    wrControl.setVisible(true);
    wrControl.setSrc(wrControlName);
    Xrm.Page.data.entity.save();

    }
    // wrControl.setFocus();
    }

    function getLocation()- used for Start Appointment button (from ribbon workbench)

    function SetActualEndTime()- used for mark complete button (from ribbon workbench)

    this is the information madam.

    Thanks 

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at

    Hi Amity,

    If I understand correctly we should not allow user to mark completed until he click the start appointment button.

    Add an Enable rule on "Mark Complete" button and make sure it is visible only when "Actual Start" is not null.

    So that users will not go further without clicking on start button. You can also add a form notification something like  "Make sure you start appointment to mark as completed".

  • amity Profile Picture
    202 on at

    Hi Dear

    Can U please give me steps ?

    i tried creating enable rule on mark complete button ...

    i dont know its not coming up like this . Do i need to add some javascripts also ?

    i think i m missing out with the steps so please can u give me steps ..

    Add an Enable rule on "Mark Complete" button and make sure it is visible only when "Actual Start" is not null...

    Thanks

    Amit

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans