Assign new user to document

i want to assign new user to issue document based on some condition , and i want this user to appear on form sidebar under assigned to.

frappe.ui.form.on(‘Issue’, {
refresh: function(frm) {
frappe.db.get_value(‘Issue’, frm.doc.name,‘_assign’, function(value) {
if (value._assign.includes(‘user2’)){
let assignArray = JSON.parse(value[“_assign”]);
assignArray.push(“user3”);
console.log(“assignArray” + assignArray);
let newAssignString = JSON.stringify(assignArray);
value[“_assign”] = newAssignString;
} else {
console.log(“Not OK”);
}
});
}
});
the result is [“user1”,“user2”,“user3”]
but user3 did not appear on
Screenshot 2023-06-13 000113

i need help please .

maybe just need to refresh the page?

Hi:

Maybe you need more flexibility … but are you aware of this?
https://docs.erpnext.com/docs/v14/user/manual/en/automation/assignment-rule

Hope this helps.

yes i am aware of this , my problem with assignment rule is that i can not assign two people on the same document …

if there is a solution for this problem i would not get into coding :slight_smile:

Hi:

Assignment rule,as far I know, assign just 1 user …

Try this in your client script / .js code:

frm.assign_to.add()
frm.assign_to.assign_to.dialog.fields_dict.assign_to.set_value( ["user1@yourdomain.com", "user2@yourdomain.com"])
frm.assign_to.assign_to.dialog.fields_dict.description.set_value("Your description ")
frm.assign_to.assign_to.dialog.fields_dict.priority.set_value("High")
frm.assign_to.assign_to.dialog.refresh()
frm.assign_to.assign_to.dialog.primary_action()

Hope this helps.

It works,sets the user in assigned_to field but does not add, so the dialog box is still open, and have to manually click on add. Also, it shows fields have missing values: Assign To.

Found Solution. Changed the code a bit.

frm.assign_to.add()
frm.assign_to.assign_to.dialog.fields_dict.assign_to.set_value(["test@gmail.com","test2@gmail.com"])
setTimeout(function() {
         frm.assign_to.assign_to.dialog.refresh();
         frm.assign_to.assign_to.dialog.primary_action();
},2);