Nintex for SharePoint Forum
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Dear Community,
I am trying to implement a javascript code, which informs(alert) a user, that a certain date field is expired when the form is opened.
So I assigned a Client-ID called "licence" to this particular date field.
The javascript code in the form looks like this:
NWF$(document).ready(function(){
var selectedText = document.getElementById('licence').value;
var selectedDate = new Date(selectedText);
var now = new Date();
if(selectedDate < now){
alert("Warning: The licence is expired");
}
});
Normally I set a Website Workflow to run daily and check if date is expired to send an E-Mail. But in this case the costumer don´t want to get a notification via E-Mail, because it isn´t necessary to know immediatly if it is expired. So i tried this approach using javascript when form is opened from a user.
Sincerely Viktor
Solved! Go to Solution.
Hi,
When you say you assigned a Client ID to your field, was it via this way?
If so, you have to change your JS code in order to set your "selectedText" variable, as below :
var selectedText = NWF$("#"+licence).val();
"licence" is a JS variable that contains the ID of the date field, not the ID of the date field itself.
Hi Pierre,
thank you for your fast answer. Yes i defined the Client ID in the way you posted.
I changed the getElementById into your suggested NWF$("#"+licence).val(); but it doesn´t work. For troubleshooting i shortend the code to output the licence value stored in the variable like this:
NWF$(document).ready(function(){
var selectedText = NWF$("#"+licence).val();
alert(selectedText);
});
The alert when opening the list item will display: undefined
You're right, I was too fast
Client ID seems to be available on the new/edit form, not on the display form.
To your needs, you could add a CSS Class to the control and change the way you get the value.
NWF$(document).ready(function(){
var hiddenField = NWF$(".licence-container input.nf-hidden-associated-control").first();
alert(hiddenField.val());
});
Hi Pierre,
it works!!!
I had to modify the now date Format, because a comparison wasn´t possible. So I resulted in this solution:
NWF$(document).ready(function(){
var hiddenField = NWF$(".licence-container input.nf-hidden-associated-control").first();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = yyyy +'-'+mm+'-'+dd+' 00:00:00Z';
if(hiddenField.val() < today){
alert("The licencedate is expired!!!")
}
});
I will mark ur last post as the answer to my question, but i still have to resolve something. The solution works fine for the display form, but the new/edit form has the alert even, if the date isn´t expired, maybe i can disable the code for these two forms...
hiddenField has no value on the new/edit form, you could evaluate its value as below :
if((hiddenField.val() !='') && (hiddenField.val() < today))
Thank you very much! Works perfect.
here is the full code:
NWF$(document).ready(function(){
var hiddenField = NWF$(".licence-container input.nf-hidden-associated-control").first();
//alert(hiddenField.val());
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //Januar ist 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = yyyy +'-'+mm+'-'+dd+' 00:00:00Z';
if((hiddenField.val()!='')&&(hiddenField.val() < today)){
alert("The licencedate is expired!!!")
}
});