assignDoc method

  1. @override
Future<RequestResponse<bool?>> assignDoc({
  1. String? assignTo,
  2. String? doctype,
  3. bool? myself = false,
  4. DateTime? dueDate,
  5. String? description,
  6. String? docName,
  7. List<String>? docNames,
  8. bool notify = false,
  9. Priority? priority,
  10. bool bulkAssign = false,
})
override

Assigns a doc or a list of docs to a particular user.

If the user is signed in, myself can be set to true where the assigned to will be the user signed in.

If multiple docs need to be assigned to a user, bulkAssign can be set to true and docNames can be used instead of docName.

Returns failure in case the doctype does not exist in the backend.

Implementation

@override
Future<RequestResponse<bool?>> assignDoc(
    {String? assignTo,
    String? doctype,
    bool? myself = false,
    DateTime? dueDate,
    String? description,
    String? docName,
    List<String>? docNames,
    bool notify = false,
    Priority? priority,
    bool bulkAssign = false}) async {
  // FIXME: possible to assign same doc twice, should be validated
  final args = AssignDocParams(
      assignTo: assignTo,
      description: description,
      myself: myself,
      dueDate: dueDate,
      doctype: doctype,
      docName: docName,
      docNames: docNames,
      priority: priority,
      bulkAssign: bulkAssign,
      notify: notify);

  args.cmd = args.bulkAssign!
      ? 'frappe.desk.form.assign_to.add_multiple'
      : 'frappe.desk.form.assign_to.add';

  if (args.myself!) args.assignTo = config.coreInstance.auth.currentUser;

  final response = await Request.initiateRequest(
      url: config.hostUrl,
      method: HttpMethod.POST,
      contentType: ContentTypeLiterals.APPLICATION_JSON,
      data: (args
            ..name =
                args.bulkAssign! ? jsonEncode(args.docNames) : args.docName)
          .toJson());
  if (response.isSuccess) {
    return RequestResponse.success(response.isSuccess);
  } else {
    return RequestResponse.fail(handleError('assign_doc', response.error));
  }
}