Add row to sales team table and copy sales person from same sales invoice

i have a field in sales invoice for selecting sales person
i want to add a row and copy that sales person in the sales team table in sales invoice
what is missing in the following script
frappe.ui.form.on(“Sales Invoice”,“refresh”, function(){
for (var i =0; i < cur_frm.doc.sales_team.length; i++){

				cur_frm.doc.sales_team[i].sales_person = cur_frm.doc.sales_person
				cur_frm.doc.sales_team[i].allocated_percentage = "100"
				}
					cur_frm.refresh_field('sales_person')

});

1 Like

Hi,
Have you found the problems ? I have the same problems here…

@Aniket_Shinde1 @alan

frappe.ui.form.on(“Sales Invoice”,“sales_person”, function(cdt,cdn,frm){
                var child = frm.add_child("sales_team");
				child.sales_person = frm.doc.sales_person
				child.allocated_percentage = "100"
			    frm.refresh_field('sales_team')
});

My case a bit different, I want to make the sales person by following the login ID.

Any advise ?

Didn’t get you. Can you explain complete use case?

I want to have default sales person by following the login ID. So I use the following code.

However, it only trigger when refresh, but cannot trigger by using different trigger, eg : onload or a field name. Any idea whats wrong with the code ?

frappe.ui.form.on(“Sales Order”, {
customer: function(frm) {

var Current_User = frappe.user_info().fullname;
var child = frm.add_child(“sales_team”);

for (var i =0; i < cur_frm.doc.sales_team.length; i++){

child.sales_person = frappe.user_info().fullname
child.allocated_percentage = “100”

  		}

frm.refresh_field(‘sales_team’)

}

});

frappe.ui.form.on('Sales Order', {
    onload: function(frm) {
        var child = frm.add_child('sales_team')
        child.sales_person = frappe.user_info().fullname
        child.allocated_percentage = 100
        frm.refresh_field('sales_team')
    }
})

Hi,
Yes its worked. When loaded the sales order, it’s able to fetch the ID as sales person.
Thanks.

However when I select customer or refresh the form, the sales person being refreshed and gone. Any idea how to workaround with this ?

frappe.ui.form.on('Sales Order', {
//    onload: function(frm) {
//	frm.doc.sales_team =[]
 //       var child = frm.add_child('sales_team')
 //       child.sales_person = frappe.user_info().fullname
 //       child.allocated_percentage = 100
  //      frm.refresh_field('sales_team')
   // },
 refresh: function(frm) {
	frm.doc.sales_team =[]
        var child = frm.add_child('sales_team')
        child.sales_person = frappe.user_info().fullname
        child.allocated_percentage = 100
        frm.refresh_field('sales_team')
    },
customer: function(frm) {
	frm.doc.sales_team =[]
        var child = frm.add_child('sales_team')
        child.sales_person = frappe.user_info().fullname
        child.allocated_percentage = 100
        frm.refresh_field('sales_team')
    }

})

Hi,
Thanks for the reply.
However, this will cause a problem, if there’s a sales order save in draft or submitted, when I enter into the sales order, it will override it too.

Other than client side script, any way that I can set up the default sales person by following the Login ID ? eg : setting at customize form ?

Thats, great.

Hi, it is not solved yet. Any further advise ?

Hi,
I have the following script, it can fetch the default login ID and update as Sales Person.

//11 AUTO FETCH SALES PERSON BASED ON LOGIN ID

frappe.ui.form.on(“Sales Invoice”, {
refresh: function(frm) {
if ( frm.doc.__islocal )
{
frm.doc.sales_team =

var child = frm.add_child(‘sales_team’)
child.sales_person = frappe.user_info().fullname
child.allocated_percentage = “100”
frm.refresh_field(‘sales_team’)
}
else
{
child.sales_person = child.sales_person
child.allocated_percentage = child.allocated_percentage
}
},
customer: function(frm) {
if ( frm.doc.__islocal )
{
frm.doc.sales_team =

var child = frm.add_child(‘sales_team’)
child.sales_person = frappe.user_info().fullname
child.allocated_percentage = “100”
frm.refresh_field(‘sales_team’)

}
else
{
child.sales_person = child.sales_person
child.allocated_percentage = child.allocated_percentage
}
}

});

However, this script seems crashed with the core file, and cause the “Make Invoice” button dissapeared. Kindly help to advise.

34%20PM