Attachment mandatory on closing task

ujjwala_678
Tera Contributor

Hey everyone,

I got a ask to make attachment mandatory on form whenever user tries to close the task....

I have a Ui action called closed that reflects the state of the task closed...The scenario here is whenever user clicks on close button he should be able to see message 'please add an attachment ' and then if attachment is present form should automatically move to closed state...Is there a way I can achieve this via ui action? I guess BR is also needed..

Could anyone can suggest me better approach here?

Thank you 😊 

5 REPLIES 5

Slava Savitsky
Giga Sage

One way to achieve this is to create a business rule that would:

  • run before State changes to Closed
  • check if the current record has at least one attachment using current.hasAttachments()
  • and abort the transaction if that is not the case.

 

Alternatively, you can combine client-side and server-side code directly in your UI action.

Hello @Slava Savitsky ,

Thank you for your response on this. Actually I would like to replicate the attachment popup functionality as we have on form headers and this should be automated...once user clicks on close button, attachment popup should appear and if user adds the attachment , task should be moved to closed state 

This is the exact ask... Just the bR and ui action is not enough...will also need to add up ui page 

Lemme know your thoughts on this,

Thank you 

Here is the client-side code to open the out-of-the-box attachment dialog:

saveAttachment(g_form.getTableName(), g_form.getUniqueValue());

You can call it from your UI action if you detect that there is no attachment.

Deepak Shaerma
Kilo Sage

Hi @ujjwala_678 

Yes, you can achieve this requirement by combining a UI Action with a Business Rule.

Step 1: Modify the UI Action

 

// On your ‘Close’ UI Action

(function executeCloseUIAction(){

    if (!g_form.hasAttachments()) {

        alert(“Please add an attachment before closing the task.”);

        return false;

    } else {

        g_form.setValue(‘state’, ‘closed’); // Adjust the state value as needed

        g_form.save();

    }

})();

 

 

Step 2: Business Rule

- When: Before

- Insert: true

- Update: true

- Filter Conditions: [State] [changes to] [Closed]

In the Script field, enter:

 

(function executeRule(current, previous /null when async/) {

    if (current.state == ‘closed’ && !current.hasAttachments()) {

        gs.addErrorMessage(‘Please add an attachment before closing the task.’);

        current.setAbortAction(true);

    }

})(current, previous);

 

please mark this Helpful and Accepted Solution if this helps you. Your action will help me and the community in understanding same requirements.

Thanks & Regards

Deepak Sharma