Need a Date Time Field to be locked upon 1st time initialization and never changed again

SpicyMcHaggis

21-04-2020

Hi, I am a complete novice with all of this, so please pretend I'm 5 years old. 

 

I have a Purchase Request form that gets circulated around my company. 


A user has the form generator on their desktop and one of the fields is a date/time field that I use to create a "serial number" for traceability. 

 

I've assigned it an action to return a serial number in the following format:

 

//+ ActionName: DateTimeField1.initialize
this.resolveNode("$").rawValue = util.printd("yyyy-mm-dd", new Date());
//-
this.resolveNode("$").rawValue = util.printd("yyyymmddHHMMss", new Date());

 

which provides the following number: 20200421113111 (year 2020, month 04, day 21, hour 11, minute 31, seconds 11). Basically, the "Serial number" is snapshot of when the form was created. 

 

This Purchase Requisition Form also has an "Email Submit Button" that will be used to send the form to the Purchasing Agents in the company. 

 

I want the form to keep the serial number (the snapshot, in this example 20200421113111) in the DateTimeField1 locked down, so when the Purchasing Agent (or anyone else) opens the form in the future, that field always reads that serial number snapshot. 

 

Is this possible? 

 

Also bonus points if when the Email Submit Button is clicked, it actually reads that serial number from the DateTimeField1 location, and saves the file as a .pdf with that serial number as the file name.

 

Can anyone help me? Thank you so much in advance. 

 

Accepted Solutions (1)

Accepted Solutions (1)

radzmar

MVP

22-04-2020

Don't use the Action Build if possible. It creates very complex scripts, that are hard to read. 

Just add  the following JavaScript with the script editor. 

if (this.isNull) {
    this.rawValue = util.printd("yyyymmddHHMMss", new Date());
}

 

Answers (1)

Answers (1)

radzmar

MVP

21-04-2020

To execute a script just once use an if expression. Here's an example.

// Only if the field is blank, execute the following script!
if (this.isNull) {
    // Put the script to be executed here!
}

 

The e-mail can be populated with values from form fields. I made a small macro, that helps you to create such script easily.

Here you go: https://thelivecycle.blogspot.com/2012/05/mailto-maker-marco-v1.html