App Maker Document approval template : How can I Add Default Approvers

非 Y 不嫁゛ 提交于 2019-11-28 14:13:46

The earlier answer points to solve the problem where user are adding stage manually. If you want all stages and all approvers list to be added automatically, follow the below steps.

  1. Open Edit Request page, in that page you can find event onAttach, this event will trigger when page is being loaded and data has not loaded yet. DMS Template has already provided a method called startLoading() to this Event.
  2. Locate startLoading() method in Client Script named EditRequestPage_Request. This method is calling loadEditRequestPage() method internally. Locate loadEditRequestPage() method.
  3. This method is adding a default stage (i.e. Stage 1) to the approval workflow. We need to perform our operations here for Automatically add approvers.
  4. Locate the line requestDs.relations.WorkflowStages.createItem in the code, this line is Adding a Stage to the workflow. So we need to add this line multiple times to Add multiple stages. In my below code I've show cased for 2 stages.

Code for adding 2 stages and 1 approver at each stage.

if (requestDs.item.WorkflowStages.length === 0) {

    requestDs.relations.WorkflowStages.createItem(function() {
    var createDatasource = requestDs.relations.WorkflowStages.relations.Approvers.modes.create;
    var draft = createDatasource.item;
    draft.Email = 'darpan.sanghavi@abc.com';
    draft.Name = 'Darpan Sanghavi';          


    createDatasource.createItem(function(createdRecord) { });

    });      

     requestDs.relations.WorkflowStages.createItem(function() {
    var createDatasource = requestDs.relations.WorkflowStages.relations.Approvers.modes.create;
    var draft = createDatasource.item;
    draft.Email = 'darpan.sanghavi@xyz.com';
    draft.Name = 'Darn Alarm';          


    createDatasource.createItem(function(createdRecord) { });
    app.closeDialog();

    }); 

}
  1. In the above code I've added lines inside requestDs.relations.WorkflowStages.createItem call, this call is creating a stage, inside a stage I've added Predefined Approver by Creating New Approver Data source.

This code still can be changed for incorporating changes like User's Thumbnail and some other changes, but this will help you get going. Add/Change code as per need.

Answer to your question :

how can I associate a new stage to an another approver

Whenever you are clicking on + ADD STAGE button, you can add your predefined approvers in method createStage. You can do so by adding Approver in request.WorkflowStages.

Try doing this. If it does not work let me know. I will try to provide you some more code.

The code from Darpan do add 2 stages and 1 approver at each stage automatically, however if you can see from the screenshot below, both Stage1 and Stage2 is under Current approval status. Which mean Stage2 approver can approve first before the Stage1 approver approve it yet. This is not correct is it?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!