cancel
Showing results for 
Search instead for 
Did you mean: 

Get raw date field in ServiceMax Mobile

Highlighted
Grill Chef
Grill Chef

Get raw date field in ServiceMax Mobile

Jump to solution

I am working on a Service Report, where we display date fields and use them to calculate the time in hours between two different date inputs.

However, it seems as if ServiceMax formats the date automatically to the system default (I guess) before I use it and so parsing it goes wrong when the date is formatted dd.mm.yyyy instead of dd-mm-yyyy.
These reports are used across the world so I'm guessing these problems will occur in many different forms, too many to manually check.

My question boils down to this:

Is it possible to retrieve the raw dates from the SQL database or can I use some for of the $F.FORMAT function to make sure there is always only one date format to worry about?

thanks in advance.

1 Solution

Accepted Solutions
Highlighted
Employee
Employee

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Jur,

Unfortunately the date that is stored in the local database is translated for the User's locale settings, so there is no way to manipulate it by using .get() methods within Javascript.  The only work around that I can think of is to create a formula field on the Work Order that points to a Custom field on the User record where you define what date format that particular user has established.  You can't "point" the formula field to the User Locale, so you would have to have a similar field that maintains this information.  Then within your function you can reference this field on the Work Order to determine which order to split up the date.  If the date is more "static" you can also create a formula field on the Work Order.

Another approach you could consider would be to create a formula field on the WO looking at the CreatedDate, something like this :

TEXT(DAY(DATEVALUE(CreatedDate))) + TEXT(MONTH(DATEVALUE(CreatedDate))) + TEXT(YEAR(DATEVALUE(CreatedDate)))

Then you can compare the CreatedDate with this formula (where you are ensured of the ordering of DDMMYYYY) and then surmise the format for the rest of the dates on the WO for that Users locale.

Sorry there isn't an easier way to do this, but we can create an enhancenemt to provide better functions.

Scott

View solution in original post

Highlighted
Product Team
Product Team

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Jur!

ServiceMax Smart Docs should default the Date Field display to the user locale when producing the data in the output document. I can see how this might impact calculations based on parsed day/month data from the field.

Can you please clarify a couple points, just to make sure I'm not completely missing the point:

  • Is your Service Report is being written through the Smart Docs transaction designer?
  • If so, are you writing the calculations into the Apex of the Smart Doc itself, or are you populating the calculation results from a formula / custom field on the record?
  • Since these calculations are based on time, are you also using the Time data on the date field?
  • Would you have the flexibility to use fields for calculations / parsing out the data of the date field currently causing you concern?

Regards,

Lacy Cotton

Regards,


Lacy Cotton-Hodgson
Product Manager
lacy.cotton@servicemax.com
Highlighted
Grill Chef
Grill Chef

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Lacy,

First of all, thanks for your swift reply.

I am using the Service Flow Manager (SFM) to create a report and using a

JavaScript function to calculate the difference in hours between two data

fields in hours, since sometimes we don'r have a connection to SalesForce

to make sure this field is populated correctly. I also use JavaScript to

display the date format in a single format (dd-MMM-yyyy):

var isTwelveHourNotation = datetimeString.indexOf("PM") > -1 ||

datetimeString.indexOf("AM") > -1;

var dateTime = datetimeString.split("\ ");

//this is where the problem occurs; Do I split at '-', '/', '.'? Is the

month presentedf first, then the date or vice versa etc.

var date = dateTime[0].split("-");

return new Date(parseInt(date[2]), parseInt(date[1]), parseInt(date[0]), 0,

0, 0, 0);

I hope this clarifies what I am trying to accomplish.

Kind regards,

Jur van Oerle.

<http://certification.salesforce.com/verification?&fullname=jur%20van%20oerle>

ABSI Nederland <http://www.absi.nl/> | Salesforce.com Developer

Orteliuslaan 850- 3528 BB Utrecht

jur.van.oerle@absi.nl <xander@absi.nl> / Tel: +31(0)6 466 13 558

Highlighted
Product Team
Product Team

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Jur,

Thanks very much for the clarification, your points make complete sense! I just want you to know I've extended your question to some fellow team members to get their expertise. I hope to have some feedback for you very soon, and hopefully an excellent best practice for other users who need to standardize their date formatting in the same way!

Regards,

Lacy Cotton

Regards,


Lacy Cotton-Hodgson
Product Manager
lacy.cotton@servicemax.com
Highlighted
Employee
Employee

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Jur,

Unfortunately the date that is stored in the local database is translated for the User's locale settings, so there is no way to manipulate it by using .get() methods within Javascript.  The only work around that I can think of is to create a formula field on the Work Order that points to a Custom field on the User record where you define what date format that particular user has established.  You can't "point" the formula field to the User Locale, so you would have to have a similar field that maintains this information.  Then within your function you can reference this field on the Work Order to determine which order to split up the date.  If the date is more "static" you can also create a formula field on the Work Order.

Another approach you could consider would be to create a formula field on the WO looking at the CreatedDate, something like this :

TEXT(DAY(DATEVALUE(CreatedDate))) + TEXT(MONTH(DATEVALUE(CreatedDate))) + TEXT(YEAR(DATEVALUE(CreatedDate)))

Then you can compare the CreatedDate with this formula (where you are ensured of the ordering of DDMMYYYY) and then surmise the format for the rest of the dates on the WO for that Users locale.

Sorry there isn't an easier way to do this, but we can create an enhancenemt to provide better functions.

Scott

View solution in original post

Highlighted
Grill Chef
Grill Chef

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Scott, thank you for your reply,

If I understand you correctly, what you want to do is to add a date field in Salesforce, which is ensured to be of a certain format and then use that date field to calculate the hours and teference it as a textfield (formula)?

If so, the problem with this approach is that it requires a connection to SalesForce, which isn't available in all cases, so I cannot actively rely on it. When a technician is done with his work, he fills in his expenses, which is then stored into the local sql datababe. Then, when generating the report, they are retrieved locally once again (as far as my understanding goes). There is no connection to SalesForce required (and as stated earlier) often it is not available.

then again, maybe I am missing your point.

I hope to be hearing from you soon.

Kind regards,

Jur van Oerle

0 Likes
Reply
Highlighted
Employee
Employee

Re: Get raw date field in ServiceMax Mobile

Jump to solution

It's a bit more involved than that.  When you are generating the report, you would look to this formula field that is based on the CreatedDate.  So for example, your locally stored CreatedDate is 11/29/2014.  The formula is 29112014, so by comparing the two dates, you know that the locally stored date is formatted as MMDDYYYY.  Based on this information you can assume that all dates are in this format, so you now know the order of the dates stored for that particular user.  If the formula returns 11292014, you know that the CreatedDate (and all other Dates) is stored locally as DDMMYYYY.

This approach does not require a connection with salesforce.  The formula fields are stored within the local database at the time of sync.  So for some formula fields this could pose a problem since the formula value could be stale, but since in this example it's based on the CreatedDate, it fulfills our needs.  The only possible issue would be if you are creating a new Work Order from the mobile device and then expect to generate the document without having saved/sync'd it first.  In this case you would not have access to the formula field since it's computed server side.

Highlighted
Grill Chef
Grill Chef

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Scott,

This sounds very promising indeed, I will look at it first thing tomorrow morning.

Thanks again for your swift and accurate answer.

Highlighted
Employee
Employee

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Cool, let us know how it works out.  I think you might need to tweak the formula a bit from what I posted since it does not display the potential leading zeros in the date.  So if the date were 01/01/2015, the formula in it's current form would display 112015.  I think you could actually get by with just outputting the month or day in the formula and adding in some logic to add the 0.  Then just compare that with the first two digits of the date. 

Highlighted
Grill Chef
Grill Chef

Re: Get raw date field in ServiceMax Mobile

Jump to solution

Hi Scott,

this is what I ended up doing and it seems to work pretty well:

I created a formula field on a Workorder with date 29-11-2015 (where you know the date and month)

and in Javascript did

var dateSplitSign;

  var datePos = 0;

  var monthPos = 0;

  var yearPos = 0;

  function setDateFormat(exampleDate)

  {

  var date = [];

  if(exampleDate.indexOf(".") > -1)

  {

  dateSplitSign = ".";

  } else if (exampleDate.indexOf("/") > -1)

  {

  dateSplitSign = "/";

  } else if (exampleDate.indexOf("-") > -1)

  {

  dateSplitSign = "-";

  }

  date = exampleDate.split(dateSplitSign);

  switch (date[1])

  {

  case "29":

  datePos = 1;

  break;

  case "11":

  monthPos = 1;

  break;

  case "2015":

  yearPos = 1;

  break;

  }

  switch (date[2])

  {

  case "29":

  datePos = 2;

  break;

  case "11":

  monthPos = 2;

  break;

  case "2015":

  yearPos = 2;

  break;

  }

  }

it's not really nice but seems to work