Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

SpicyMcHaggis
Level 1
Level 1

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. 

 

1 Accepted Solution
radzmar
Correct answer by
Level 10
Level 10

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());
}

 

View solution in original post

4 Replies
radzmar
Level 10
Level 10

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

 

SpicyMcHaggis
Level 1
Level 1

Hi Radzmar,

 

Thanks for the response, I really really appreciate it. Like I said, I'm pretty new at this. 

 

So I've taken what did look like this:

 

topmostSubform.Page1.DateTimeField1::initialize - (JavaScript, client)
//+ GENERATED - DO NOT EDIT (ID:B8F51925-FDEE-463A-A99D-9ECC39F9124A CRC:1146231519)
//+ Type: Action
//+ Result1: SetFieldValue("$Node1","totoday","")
//+ Node1: topmostSubform[0].Page1[0].DateTimeField1[0]
//+ Condition1: DateField("$Node1","initialized","")
//+ ActionName: DateTimeField1.initialize
this.resolveNode("$").rawValue = util.printd("yyyy-mm-dd", new Date());
//-
this.resolveNode("$").rawValue = util.printd("yyyymmddHHMMss", new Date());

 

and based on what you've said, I've changed it to this:

 

topmostSubform.Page1.DateTimeField1::initialize - (JavaScript, client)
if (this.isNull) {this.resolveNode("$").rawValue = util.printd("yyyy-mm-dd", new Date())};
this.resolveNode("$").rawValue = util.printd("yyyymmddHHMMss", new Date());

 

Is that the intent? 

radzmar
Correct answer by
Level 10
Level 10

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());
}

 

View solution in original post