Пример предоставил t.me/sabir_safarov
Может, кому-то будет интересно. Нужно было присвоить текущего пользователя во время создания элемента приложения. Вкратце: берем табличку, разбиваем ее по строкам, из каждой строки формируем элемент приложения типа события (календарик).
Код:
Код:
async function table_up(): Promise<void> {
const length_day = (Context.data.end_period!.asDatetime(new TTime(0, 0, 0, 0)).unix() - Context.data.start_period!.asDatetime(new TTime(0, 0, 0, 0)).unix()) / (24 * 60 * 60) ;
Context.data.bp_length_day = length_day;
const generalSettings = await System.productionSchedule.getGeneralSettings();
let start_time = generalSettings.daySchedule.workingTime.from;
let start_time_minute = (start_time/ 60) % 60;
let start_time_hour = Math.floor((start_time / 60) / 60);
const start_time_ttime = new TTime(start_time_hour,start_time_minute,0,0);
let end_time = generalSettings.daySchedule.workingTime.to;
let end_time_minute = (end_time/ 60) % 60;
let end_time_hour = Math.floor((end_time / 60) / 60);
const end_time_ttime = new TTime(end_time_hour,end_time_minute,0,0);
for(let i = 0;i <= length_day; i++){
let row = Context.data.bp_date_and_time!.insert()
row.bp_table_data = Context.data.start_period!.addDate(0,0,i);
row.bp_table_time_start = start_time_ttime;
row.bp_table_time_end = end_time_ttime;
}
}
async function app(): Promise<void> {
const table = Context.data.bp_date_and_time!.map(f => f);
const generalSettings = await System.productionSchedule.getGeneralSettings();
let start_time = generalSettings.daySchedule.workingTime.from;
let start_time_minute = (start_time/ 60) % 60;
let start_time_hour = Math.floor((start_time / 60) / 60);
const start_time_ttime = new TTime(start_time_hour,start_time_minute,0,0);
let end_time = generalSettings.daySchedule.workingTime.to;
let end_time_minute = (end_time/ 60) % 60;
let end_time_hour = Math.floor((end_time / 60) / 60);
const end_time_ttime = new TTime(end_time_hour,end_time_minute,0,0);
for(let table_for of table){
// if(table_for.bp_table_time_start !== start_time_ttime && table_for.bp_table_time_end !== end_time_ttime){
let order = Context.fields.prilozhnie_grafik.app.create();
let year_start = table_for.bp_table_data!.year.toString();
let month_start = table_for.bp_table_data!.month.toString();
let day_start = table_for.bp_table_data!.day.toString();
let hours_start = table_for.bp_table_time_start!.hours;
let minutes_start = table_for.bp_table_time_start!.minutes.toString();
hours_start = hours_start - 3;
let hours_start_sr = hours_start!.toString();
if(minutes_start == '0'){
minutes_start = "00";
}
let dataStart = new Datetime( day_start+'.'+month_start+'.'+year_start+' '+hours_start+':'+minutes_start,'DD.MM.YYYY HH:mm');
let hours_end = table_for.bp_table_time_end!.hours;
let minutes_end = table_for.bp_table_time_end!.minutes.toString();
hours_end = hours_end - 3;
let hours_end_sr = hours_end!.toString();
if(minutes_end == '0'){
minutes_end = "00";
}
let dataEnd = new Datetime( day_start+'.'+month_start+'.'+year_start+' '+hours_end_sr+':'+minutes_end,'DD.MM.YYYY HH:mm');
order.data.__startAt = dataStart;
order.data.__endAt = dataEnd;
const allowedGroup = await System.userGroups.search().where(a => a.__name.like('Согласующий изменения в графике')).first();
const usersInAllowedGroup = await allowedGroup!.users(0,1);
order.data.__participants = [];
order.data.__participants.push(Context.data.user!);
order.data.__name = '122212';
await order.save();
}