I have to store attachment based on year inside uploads folder. My primary key is not running numbers its is format like EMC-03-24-1. while row_inserting i passed this REQUEST_NO into a session variable. But it is taking in userfn as previously inserted REQUEST_NO. How to fix it? is there any alternative option to upload in a dynamic folder?
Dynamic folder for file upload
-
- User
- Posts: 9476
What did you mean by "based on year"? If "year" is a field and it always has data, you may try set the field's upload folder as $this->year->DbValue . "/"
. (You should not use session variable unless you are sure that the session variable will exist when you retrieve the record.)
-
- User
- Posts: 12
this is the code inside userfn
function get_emc_date() {
$page = CurrentPage();
$emc_date = NULL;
$emcno = $page->ENV_REQUEST_NO->DbValue;
if (strlen($emcno) == 0)
$emc_date = $page->REQUEST_DATE->DbValue;
else
$emc_date = ew_ExecuteScalar("SELECT REQUEST_DATE FROM env_test_req_form WHERE ENV_REQUEST_NO = '$emcno'");
return date('Y', strtotime($emc_date));
}
in attachment filed i added this function value there inside upload folder
-
- User
- Posts: 9476
Then you may put your function in Global Code and use your function as the field's upload folder, e.g. get_emc_date() . "/"
.
-
- User
- Posts: 12
this is not working properly. i think because of the primary key not Auto Increment. It is like EMC-03-24-1. So I have to store this into session while inserting and session want to use in global code but that also not working properly. now the $emcno = $page->ENV_REQUEST_NO->DbValue; getting null. Is there any idea for that. Thank You
-
- User
- Posts: 9476
arbei wrote:
You should not use session variable unless you are sure that the session variable will exist when you retrieve the record.
When you insert a new record, you need to make sure the field "ENV_REQUEST_NO" has value. You may use Row_Inserting event to set a value if it is not set yet.
-
- User
- Posts: 9476
athira wrote:
i set like this $rsnew['ENV_REQUEST_NO'] = 'EMC-'.$month.'-'.$year.'-'.$count;
For exactly the same reason as:
You should not use session variable unless you are sure that the session variable will exist when you retrieve the record.
You need to make sure the same values of $month
, $year
, and $count
exist when you retrieve the record. (You should not use current month, year and count.)