- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2017 03:04 AM
Hi Snow Enthusiasts,
I'm trying to calculate difference between two dates viz. planned_start and planned_end. This difference I need to out in the duration field on the same form.
Pretty common I know. Very common as their are ample scripts as OOB and in community as well. The problem with me is I'm working in a completely scoped environment and not sure if I'm doing everything correct. So the process is :
Issue : final variable gives NULL value.
1. An onChange client script on Planned End Date (planned_end)
2. CS code :
Commented lines will give you an idea what are other variations I have tried.
2. Common Script Include (scoped environment) :
Again commented lines will give you what are the other variations I tried here.
The "ans2" variable in the client script gives me a NULL value.
Please guide me to enlightenment.
Thanks,
Arnab
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 02:17 AM
Hi All,
I could figure out what was actually resulting the output to be NULL.
Since I'm working on a scoped app as I had mentioned, the gs.dateDiff() function does not work in the scoped environment. The AJAX call is directed to a script include which too was in the scoped environment. Hence the difference of the dates were not calculated and NULL was the output.
What I did to resolve :
From the scoped script include I called a another Script Include in the GLOBAL scope and it was there I used the gs.dateDiff() to calculate the difference and return the result to the script include in scoped environment. Now I was able to get the required value and set it in the Duration field in the client script on the desired form.
Thanks to all of you. Ever Helping guys.
On this context if I can make a request of a link or a document which mentions all the functions and classes that are not available in a private scope.
Thanks,
Arnab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2017 04:31 AM
Hi Mihir,
Thanks for your participation.
Yes the Client callable check box is checked. Also it is accessible from all scopes.
The script include is a generic one where we direct all our ajax calls in our scoped environment.
Please let me know what else could be done.
Thanks,
Arnab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2017 01:06 AM
Hi All,
Anyone active on this.
Thanks,
Arnab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2017 01:29 AM
Arnab Dey wrote:
Hi Snow Enthusiasts,
I'm trying to calculate difference between two dates viz. planned_start and planned_end. This difference I need to out in the duration field on the same form.
1. An onChange client script on Planned End Date (planned_end)
There's your first problem.
Dates fetched from the database are presented as text in the user format, so getValue() actually returns a String, which could be presented in a variety of formats.
Any manipulation client-side will involve the following steps:
- obtain the user-settable date format
- use that format to convert a string to a date object
- perform date calculations against date objects.
It's a common challenge, and I see many posts on this board from people either making assumptions that their users will never customise their date format, or forcing users to adopt a fixed format because it's easier for developers to manipulate durations (i.e.: needs of the few developers outweigh the productivity of their many users, something I vehemently disagree with)
For accuracy, you may want a business rule to manipulate the dates server-side then display client-side. Unfortunately this means involving a round trip rather than instant feedback, but on the server you can at least guarantee accuracy since custom user presentation format can be safely ignored.
An alternative is to pass dates in standard format the scratchpad so there is something client-side to manipulate, but again you may have issues with the user-entered date conversion.
I'm not sure if there's any pre-written code that can convert client-side strings to javascript date objects, but it'd be useful if so.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 02:17 AM
Hi All,
I could figure out what was actually resulting the output to be NULL.
Since I'm working on a scoped app as I had mentioned, the gs.dateDiff() function does not work in the scoped environment. The AJAX call is directed to a script include which too was in the scoped environment. Hence the difference of the dates were not calculated and NULL was the output.
What I did to resolve :
From the scoped script include I called a another Script Include in the GLOBAL scope and it was there I used the gs.dateDiff() to calculate the difference and return the result to the script include in scoped environment. Now I was able to get the required value and set it in the Duration field in the client script on the desired form.
Thanks to all of you. Ever Helping guys.
On this context if I can make a request of a link or a document which mentions all the functions and classes that are not available in a private scope.
Thanks,
Arnab