Here's the issue with Podio. I have a calculation field that is set to return a date and it does that well if I only enter a reference to a date field from the item. What I want is for the calculation field to return a null date (as part of an IF statement) and thus leave or make the field empty (and therefore not show up in the calendar).
Something like this:
var date = DateFieldFromPodioItem;
if (whatever) {
moment(date).add(2, "weeks").toDate();
}
else {
//RETURN NULL HERE
};
I have tried setting var zero = null and have it return that. Which yields me an Invalid date error.
I also tried using .setFullYear(null,null,null) along with .setHours(null,null,null,null) to set date and return that. I set date to 1 January 0001 12:00:00.000 AM as was suggested somewhere (I forgot where I read that). The first got me a rather unfriendly: Invalid value datetime.datetime(1753, 9, 12, 22, 43, 41, 128000) (datetime): Dates before year 1900 are not supported. The second did too, with slightly different numbers within the ().
I even tried the rather silly idea of entering no code within else, but that also returns Invalid date.
Any ideas?
----EDIT----
Turns out that even while Podio shows the message Invalid date it lets you save the field anyway and when changing field values so if=false it shows no longer a date in the calculation field. Thanks to Rainer Grabowski for pointing that out to me. If someone #Podio reads this, perhaps fix that?
I'll leave this here to perhaps help someone else, as I have found the answer to my questions on here rather often.
Should work, but I didn't test:
var date = DateFieldFromPodioItem;
var returnValue = null;
if (whatever) {
returnValue = moment(date).add(2, "weeks").toDate();
}
returnValue;
Related
I want to achieve the following, restrict changing a date field to further date from its current value, in Dynamics CRM via JavaScript.
Below is my JavaScript code, im pretty new to JavaScript Dynamics development, below is my code, by the way its not throwing an alert, is it coded properly? - apologies if the question doesnt make sense.
Why isn't it throwing an alert, when I enter a date future from current value?
function test(executionContext) {
formContext = executionContext.getFormContext();
var fielddate = formContext.getAttribute('fielddate').getValue();
if (fielddate != null) {
fielddate.setHours(0, 0, 0, 0);
//The current date
var currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
if (fielddate > currentDate) {
alert("You can't enter future date");
}
}
}
the JavaScript code is correct, you may want to check the field name (the one you are assigning to fielddate variable) because if it's null then your code is not executed.
Instead of alert I would write
Xrm.Navigation.openAlertDialog(text: "You can't enter future date");
because it's the supported way to display alerts (https://learn.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openalertdialog)
after the message you should also clear the field, so the user can set a new value (otherwise the wrong value will be stay there)
formContext.getAttribute('fielddate').setValue(null);
I am intending to use a datapicker that does not allow the user to choose previous days before today, but I do want that today itself is available. I did this:
<input
name = "availabilityFrom"
onChange = {(e) => handleDateIn (e.target.value, e.target.name)}
type = "date"
/>
I am working with React so this above is part of a component, that has a state. Then with the value taken, I stored it on a variable to use its valueOf (), and created today´s variable also. Please notice that this.state.filterBy.availabilityFrom holds the value of the target, the selected date on the datapicker.
let today = new Date().valueOf();
let availabilityFromToDate = new Date(this.state.filterBy.availabilityFrom.split("-").join(",")).valueOf();
Then I used a conditional statement to get the desired behavior of the alert:
if (availabilityFromToDate <today && availabilityFromToDate)
{
sweetAlert ("Warning!",
"The entry date must be after the current date";
"warning");
}
It works well, I got so happy when it did. But if I choose today's date, I got the alert message anyway, even if I am not using <= for today.
Maybe I am not understanding the proper use of valueOf (). Been having nightmares about this, haha.
Thanks in advance!: D
Whenever I try to reset a date input using JavaScript, like so:
//input_id is an id of a date input
document.getElementById(input_id).value = "0000-00-00";
I get a warning in the console:
The specified value "0000-00-00" does not conform to the required format, "yyyy-MM-dd".
Does anyone know a way to suppress this warning so it won't show? The JS keeps on running smoothly but I want to get rid of these warnings.
If you have another way of resetting a date input (without raising a warning) I will be happy to hear.
Thanks in advance.
You're getting the warning because years, months, and days start at 1, not 0. 0 is an invalid value for all of them. But there's a simpler way to reset an input element..
You can just set the value to the empty string which is the initial default value.
var di = document.createElement("input");
di.type = "date";
console.log(di.value); // outputs ""
document.body.appendChild(di);
// change the value if you want
// to reset:
di.value = "";
You can assign a empty string value
document.getElementById(input_id).value = "";
At the bottom of your Javascript call
console.clear();
This clears all warnings and errors from your console.
You can also replace console.warn with your own code like:
console.warn = function () { };.
NOT recommended because you will not get any warnings to your console this way.
I'm having difficulty setting a time (duration) value in a datebox. A simple demonstration of the problem is if I do something like:
function initDuration() {
this.d['header Text'] = "Set";
this.d['headerText'] = "Set Duration";
var element = 'input#'+this.element[0].id;
var currentDt = $(element).datebox('getTheDate');
// ***************
var dt = $(element).datebox('parseDate', '%H:%M', this.element[0].value); // Where this.element[0].value = "01:00:00"
// ***************
$(element).datebox('setTheDate', this.element[0].value);
$(element).trigger('datebox', { 'method': 'doset' });
}
dt just contains the current date/time; i.e. jtsage didn't like it. The element is defined (in jade) as:
input.Duration(type="text" name="duration" form="form#{i}"
id="duration#{i}" value="#{map[i].duration}" data-role="datebox"
data-options=
'{"mode":"durationflipbox", "overrideDurationOrder":["h","i"],'
+' "overrideTimeFormat": "%l:%M", "minuteStep":15, "beforeOpenCallback": "initDuration"}')
Also I'm not sure how to change the flipbox title. The 2nd line in initDuration() sets the text for the button but the title still says 'Set Time'.
Because of the first problem the last 2 lines in initDuration() don't do what I want. i.e. they just use the current time, whatever that happens to be.
My apologies that this is going to be an incomplete answer, but it was going to be too long for a comment.
For the title - give "overrideHeaderText" a shot instead. It is entirely possible that I screwed this up at some point, it's not a feature I use in any of my own projects.
Next...
var dt = $(element).datebox('parseDate', '%H:%M', this.element[0].value); // Where this.element[0].value = "01:00:00"
I think I am reading you correctly that "dt" isn't containing what you are expecting. It's because 01:00:00 != %H:%M - to read this "format", you'd need to either use "%H:%M:%S" or "%H:%M:00" (the later ignoring the seconds field).
That said, I think what you are trying to do is set a duration, which, is a little different. There are a few ways to do it - and I'm noticing that there isn't a lot of support to do it functionally. The simplest method, is the set the value of the input, and let datebox handle the math - just be aware that the format you drop into the input must be exactly the same as the output format - it will read it when the control opens (or is initialized if the control is being shown inline - if you are doing it inline, and set the value "later", you can use the 'refresh' method to update it).
For what it's worth, if you really, really, really want to use the setTheDate method, duration modes work by comparing "theDate" (the publicly available date, i.e. setTheDate, getTheDate) with an internal initDate - which is not exposed to the API, but can be found here:
$(element).data('jtsage-datebox').initDate
So, in pseudo-code, for a duration of an hour
myNewDate = $(element).data( 'jtsage-datebox' ).initDate;
myNewDate.setHour( myNewDate.getHour() + 1 );
$(element).datebox( 'setTheDate', myNewDate );
I am using the following code to remove commas from an integer (whole number) field in CRM 2011:
function Form_onload()
{
document.getElementById("new_universalid").value =Xrm.Page.data.entity.attributes.get("new_universalid").getValue();
}
The issue is that for any accounts/contacts w/out a value for 'new_universalid', it's displaying the word "null".
My goal is to display a blank field, rather than the word NULL.
Thanks in advance for any suggestions.
The simplest way I can explain it and that is most obvious to understand is as follows, simply check to make sure the value is not null before assigning:
function Form_onload()
{
var new_uid=Xrm.Page.data.entity.attributes.get("new_universalid").getValue();
if(new_uid != null){
document.getElementById("new_universalid").value = new_uid;
}
}