Hi Folks,
This is a repost from a direct message thread between @MegaJerk and me that we thought would be useful to others in the community.
I need to dynamically populate the title field of list items. The string will be comprised of a selected date from the form, the selected frequency from a choice control, some literal string characters, and the date and time that the save/submit button is clicked. additionally, once the field is set, it should not be updated by subsequent saves. Huge kudos to @MegaJerk for his patient assistance with this and his "above and beyond" level of explanation to help me learn JavaScript and how to apply it to Nintex Forms!
-------------------------------
I have been messing with this and here is what I have come up with to get the date formats how I need them to be. The record name is NOT dependent on the item ID so I am good with naming it at "save time".
//======================================= // Set the Consolidated CDRL Report Name //======================================= var curDate = new Date(); function formatDatePart(myNum) { let result; if (String(myNum.length) > 1) { result = myNum; } else { result = "0" + myNum; } return result; } var ccrName = String(jsvar_ReportDate_DTE.getFullYear()) + formatDatePart(String(jsvar_ReportDate_DTE.getMonth() + 1)) + formatDatePart(String(jsvar_ReportDate_DTE.getDate())) + " - Consolidated CDRL Report (" + jsvar_Frequency_CHO + ") - " + String(curDate.getFullYear()) + "-" + formatDatePart(String(curDate.getMonth() + 1)) + "-" + formatDatePart(String(curDate.getDate())) + "-" + formatDatePart(String(curDate.getHours())) + ":" + formatDatePart(String(curDate.getMinutes())) + ":" + formatDatePart(String(curDate.getSeconds())); function setCCRName() { NWF$("#" + jsvar_CCRName_SLT).val(ccrName); }
I am just putting this code at the end of my JavaScript file (stored in the site assets library) as we have built it so far. Here is what I would like to know/understand..
1. How dry is this code? Have I reached around my elbow to scratch my ear?
2. How do I make the setCCRName() function run at the time the record is saved so the the last part of the string (the current time of the save) is accurate?
3. What "gotchas" do I need to be aware of that can come back and bite me when the user dose not act as expected?
Thanks for the help!
Best Regards,
Patrick
Best answer by MegaJerk
View original