【问题标题】:Include automation schedule definition in customization project在定制项目中包含自动化计划定义
【发布时间】:2018-02-16 21:50:37
【问题描述】:

我有一个通常会安排好的处理屏幕。我想在定制项目中包含一个不活动的计划定义,以使客户更容易。我无法在自定义屏幕中找到添加自动化的选项。有什么办法吗?

【问题讨论】:

  • 如果没有选项,您可以使用自定义插件并在包发布后使用计划图创建记录。
  • 我听说可以在自定义项目中通过脚本添加数据。你知道怎么做吗?您能描述一下自定义插件是什么意思吗?

标签: automation customization acumatica


【解决方案1】:

如果没有开箱即用的选项将特定实体包含到自定义项目中,您可以创建一个自定义插件,该插件将在发布过程结束时执行。该插件可用于与 DAC 和 Graph 配合使用,以根据需要插入、更新、删除数据。这比使用 SQL 脚本作为其 DBMS 中立(与 SQL Server 或 MySQL 一起使用)更可取。

这里是一篇帮助文章添加插件到自定义项目: To Add a Customization Plug-In to a Project

对于添加自动化计划的具体问题,您可以使用与该页面相关的图表,即AUScheduleMaint。下面是一个工作示例,用于将 Release IN Documents (IN501000) 添加为非活动计划(如果计划尚不存在)作为示例。替换屏幕 ID 和描述以满足您的需求。如果您需要与默认设置不同的计划设置,请根据需要修改 AUSchedule 的插入。

public class MyCustomPlugin : CustomizationPlugin
{

    //This method executed after customization was published and website was restarted.  
    public override void UpdateDatabase()
    {
        CreateSchedule("IN501000", "My New IN501000 Schedule");
    }

    /// <summary>
    /// Create a schedule for a given screen if the screen doesn't have a schedule
    /// </summary>
    /// <param name="screenID">Sitemap screen ID</param>
    /// <param name="scheduleDesc">Schedule description when creating a new schedule</param>
    protected virtual void CreateSchedule(string screenID, string scheduleDesc)
    {
        if (string.IsNullOrWhiteSpace(screenID))
        {
            throw new ArgumentNullException("screenID");
        }

        if (string.IsNullOrWhiteSpace(scheduleDesc))
        {
            throw new ArgumentNullException("scheduleDesc");
        }

        var auScheduleGraph = PXGraph.CreateInstance<PX.SM.AUScheduleMaint>();

        var schedule = FindScheduleByScreen(auScheduleGraph, screenID);

        if (schedule != null)
        {
            //schedule exists, no need to create...
            return;
        }

        auScheduleGraph.Schedule.Insert(new PX.SM.AUSchedule
        {
            ScreenID = screenID,
            Description = scheduleDesc,
            IsActive = false,
            StartTime = PX.Common.PXTimeZoneInfo.UtcNow
        });

        auScheduleGraph.Actions.PressSave();

        this.WriteLog(string.Format("Created automation schedule '{0}' for screen '{1}'", scheduleDesc, screenID));
    }

    /// <summary>
    /// Find an automation schedule by screen ID
    /// </summary>
    /// <param name="graph"></param>
    /// <param name="screenID"></param>
    /// <returns></returns>
    protected virtual PX.SM.AUSchedule FindScheduleByScreen(PXGraph graph, string screenID)
    {
        PX.SM.AUSchedule auSchedule = null;

        foreach (PX.SM.AUSchedule result in PXSelect<PX.SM.AUSchedule, Where<PX.SM.AUSchedule.screenID, Equal<Required<PX.SM.AUSchedule.screenID>>>>.Select(graph, screenID))
        {
            if (auSchedule == null)
            {
                auSchedule = result;
                continue;
            }

            if (result.IsActive.GetValueOrDefault() && !auSchedule.IsActive.GetValueOrDefault())
            {
                //Find an active if possible
                auSchedule = result;
            }
        }

        return auSchedule;
    }
}

【讨论】:

  • 这太棒了。感谢您的详细信息。一个小问题,我似乎无法将时间间隔设置为 15 分钟。我能找到的一切都告诉我它只是一个短整数,但是当我设置 Interval = 15 时,尝试添加行时出现错误。我什至尝试过 (Int16?) 和 (short?) 都没有运气。我还尝试在 CodeRepository 中找到图形和 DAC,但它们似乎不可见。
  • 我认为要设置间隔,您还必须设置结束时间字段。您是否设置了结束时间字段?
  • 你是对的!我试图在表格中输入它,但错误显示我需要一个结束时间。再次感谢。
  • 没问题。我总是通过我在 UI 中的输入来最好地确定我需要设置的字段值。很高兴这有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 2017-02-02
  • 2014-09-24
  • 2016-07-07
  • 2016-11-12
  • 1970-01-01
相关资源
最近更新 更多