google-app-maker

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


I use document approval template, and I want to define default approver and stages.

I have tried to change the custom value associates to the userpicker widget in EditRequest Page to define a default Approver by changing the location from onValueChange to onAttach. I set default value for mail's approvers.

PageEditRequest/userPickerWidget: PageEditRequest/userPickerWidget

Function associates to the custom value of userPickerWidget: Function associates to the custom value of userPickerWidget

But I don't know how can I associate a new stage to an another approver...

I tried a lot of things that failed

Have you any ideas?

I want to have this type of results without any client interaction:

Desired result: Desired result


Solution

  • 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.