Most often, when creating files directly in Dynamics 365FO or Dynamics AX, you need to add a timestamp to the file name.
A quick way to do this is the following method:
/// <summary>
/// create TimeStamp string
/// </summary>
/// <returns>timestamp string</returns>
private str getTimeStamp()
{
int time;
str s;
time = timenow();
s = date2Str(today(),
321,
DateDay::Digits2,
DateSeparator::None, // no separator
DateMonth::Digits2,
DateSeparator::None, // no separator
DateYear::Digits4
);
return s + "_" +
num2str0(time div 3600 ,2,0,0,0) + "_" +
num2Str0(time mod 3600 div 60,2,0,0,0) + "_" +
num2Str0(time mod 3600 mod 60,2,0,0,0);
}
On Dyn365, to avoid BP errors you can use the following code snippet:
time = DateTimeUtil::getTimeNow(DateTimeUtil::getUserPreferredTimeZone());